Skip to content

Commit 9f01d4c

Browse files
committed
fix: Fail when last health check attempt fails
1 parent 7f70585 commit 9f01d4c

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

  • workflow/deployer-workflow

workflow/deployer-workflow/impl-flyio/src/lib.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,24 @@ fn launch_final_vm(app_name: &str) -> Result<(), AppInitModifyError> {
266266
.map_err(AppInitModifyError::FinalVmError)
267267
}
268268

269+
fn check_health(app_name: &str, max_healthcheck_attempts: u32) -> Result<(), AppInitModifyError> {
270+
for _ in 0..max_healthcheck_attempts {
271+
match http_get::get_resp(&format!(
272+
"https://{app_name}.fly.dev:{HEALTHCHECK_EXTERNAL_PORT}"
273+
)) {
274+
Ok(http_get::Response {
275+
status_code,
276+
body: _,
277+
}) if (200..300).contains(&status_code) => {
278+
return Ok(());
279+
}
280+
_ => {}
281+
}
282+
workflow_support::sleep(ScheduleAt::In(SchedulingDuration::Seconds(1)));
283+
}
284+
Err(AppInitModifyError::HealthCheckFailed)
285+
}
286+
269287
fn cleanup(app_name: &str, modify_error: AppInitModifyError) -> AppInitError {
270288
if matches!(
271289
modify_error,
@@ -321,21 +339,8 @@ impl Guest for Component {
321339
)?;
322340
// All preparation is done, start the final VM.
323341
launch_final_vm(&app_name)?;
324-
325-
for _ in 0..max_healthcheck_attempts {
326-
match http_get::get_resp(&format!(
327-
"https://{app_name}.fly.dev:{HEALTHCHECK_EXTERNAL_PORT}"
328-
)) {
329-
Ok(http_get::Response {
330-
status_code,
331-
body: _,
332-
}) if (200..300).contains(&status_code) => {
333-
break;
334-
}
335-
_ => {}
336-
}
337-
workflow_support::sleep(ScheduleAt::In(SchedulingDuration::Seconds(1)));
338-
}
342+
// Make sure it is up.
343+
check_health(&app_name, max_healthcheck_attempts)?;
339344
Ok(())
340345
}
341346

workflow/deployer-workflow/wit/obelisk-flyio_workflow@1.0.0-beta/types.wit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface types {
5656
app-deleted,
5757
/// Cannot start the final VM
5858
final-vm-error(string),
59+
health-check-failed,
5960
/// Trap (panic) during execution
6061
execution-failed,
6162
}

0 commit comments

Comments
 (0)