@@ -185,22 +185,25 @@ fn cleanup(app_name: &str, modify_error: Option<AppInitModifyError>) -> AppInitE
185185 }
186186}
187187
188+ fn app_create ( org_slug : & str , app_name : & str ) -> Result < ( ) , AppInitError > {
189+ // Create the app
190+ // If the app already exists, fail with AppNameConflict
191+ if activity_fly_http:: apps:: get ( app_name)
192+ . map_err ( AppInitError :: AppCreateError ) ?
193+ . is_some ( )
194+ {
195+ return Err ( AppInitError :: AppNameConflict ) ;
196+ }
197+ // Create the app
198+ activity_fly_http:: apps:: put ( org_slug, app_name) . map_err ( AppInitError :: AppCreateError ) ?;
199+ Ok ( ( ) )
200+ }
201+
188202impl Guest for Component {
189- fn app_init_no_cleanup_on_error (
190- org_slug : String ,
203+ fn app_modify_no_cleanup_on_error (
191204 app_name : String ,
192205 config : ObeliskConfig ,
193206 ) -> Result < Vec < String > , AppInitNoCleanupError > {
194- // If the app already exists, fail with AppNameConflict
195- if activity_fly_http:: apps:: get ( & app_name)
196- . map_err ( AppInitNoCleanupError :: AppCreateError ) ?
197- . is_some ( )
198- {
199- return Err ( AppInitNoCleanupError :: AppNameConflict ) ;
200- }
201- // Create the app
202- activity_fly_http:: apps:: put ( & org_slug, & app_name)
203- . map_err ( AppInitNoCleanupError :: AppCreateError ) ?;
204207 app_modify_without_cleanup ( & app_name, config)
205208 . map_err ( AppInitNoCleanupError :: AppInitModifyError )
206209 }
@@ -211,22 +214,13 @@ impl Guest for Component {
211214 config : ObeliskConfig ,
212215 sleep_between_retries_seconds : u32 ,
213216 ) -> Result < ( ) , AppInitError > {
217+ app_create ( & org_slug, & app_name) ?;
214218 // Launch a child workflow by using import
215- let required_secrets = workflow_import:: app_init_no_cleanup_on_error (
216- & org_slug, & app_name, & config,
217- )
218- . map_err ( |err| match err {
219- AppInitNoCleanupError :: AppCreateError ( err) => {
220- // No cleanup needed, app creation failed.
221- AppInitError :: AppCreateError ( err)
222- }
223- AppInitNoCleanupError :: AppNameConflict => {
224- // No cleanup needed, app creation failed on name conflict.
225- AppInitError :: AppNameConflict
226- }
227- AppInitNoCleanupError :: AppInitModifyError ( err) => cleanup ( & app_name, Some ( err) ) ,
228- AppInitNoCleanupError :: ExecutionFailed => cleanup ( & app_name, None ) ,
229- } ) ?;
219+ let required_secrets = workflow_import:: app_modify_no_cleanup_on_error ( & app_name, & config)
220+ . map_err ( |err| match err {
221+ AppInitNoCleanupError :: AppInitModifyError ( err) => cleanup ( & app_name, Some ( err) ) ,
222+ AppInitNoCleanupError :: ExecutionFailed => cleanup ( & app_name, None ) ,
223+ } ) ?;
230224 // Sleep until all requested secrets are stored in the app.
231225 let required_secrets: HashSet < _ > = required_secrets. into_iter ( ) . collect ( ) ;
232226 while !required_secrets. is_empty ( ) {
0 commit comments