@@ -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+
269287fn 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
0 commit comments