@@ -74,6 +74,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
7474 }
7575
7676 const finalizeService = new FinalizeDeploymentService ( ) ;
77+ const templateService = new ComputeTemplateCreationService ( ) ;
7778
7879 if ( body . skipPushToRegistry ) {
7980 logger . debug ( "Skipping push to registry during deployment finalization" , {
@@ -83,7 +84,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
8384 let templateMode : "required" | "shadow" | "skip" = "skip" ;
8485 if ( deployment . imageReference ) {
8586 templateMode = await this . #handleTemplateCreation( {
86- templateService : new ComputeTemplateCreationService ( ) ,
87+ templateService,
8788 projectId : deployment . worker . project . id ,
8889 imageReference : deployment . imageReference ,
8990 deploymentFriendlyId : id ,
@@ -95,14 +96,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
9596 const result = await finalizeService . call ( authenticatedEnv , id , body ) ;
9697
9798 if ( templateMode === "shadow" && deployment . imageReference ) {
98- const shadowService = new ComputeTemplateCreationService ( ) ;
99- shadowService . createTemplate ( deployment . imageReference ) . catch ( ( error ) => {
100- logger . error ( "Shadow compute template creation failed" , {
101- id,
102- imageReference : deployment . imageReference ,
103- error : error instanceof Error ? error . message : String ( error ) ,
104- } ) ;
105- } ) ;
99+ this . #fireShadowTemplateCreation( templateService , deployment . imageReference , id ) ;
106100 }
107101
108102 return result ;
@@ -172,7 +166,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
172166 } ) ;
173167
174168 const templateMode = await this . #handleTemplateCreation( {
175- templateService : new ComputeTemplateCreationService ( ) ,
169+ templateService,
176170 projectId : deployment . worker . project . id ,
177171 imageReference : deployment . imageReference ,
178172 deploymentFriendlyId : id ,
@@ -184,14 +178,7 @@ export class FinalizeDeploymentV2Service extends BaseService {
184178
185179 // Shadow mode: fire-and-forget template creation after deploy is finalized
186180 if ( templateMode === "shadow" ) {
187- const shadowService = new ComputeTemplateCreationService ( ) ;
188- shadowService . createTemplate ( deployment . imageReference ) . catch ( ( error ) => {
189- logger . error ( "Shadow compute template creation failed" , {
190- id,
191- imageReference : deployment . imageReference ,
192- error : error instanceof Error ? error . message : String ( error ) ,
193- } ) ;
194- } ) ;
181+ this . #fireShadowTemplateCreation( templateService , deployment . imageReference , id ) ;
195182 }
196183
197184 return finalizedDeployment ;
@@ -248,6 +235,20 @@ export class FinalizeDeploymentV2Service extends BaseService {
248235
249236 return mode ;
250237 }
238+
239+ #fireShadowTemplateCreation(
240+ templateService : ComputeTemplateCreationService ,
241+ imageReference : string ,
242+ deploymentFriendlyId : string
243+ ) {
244+ templateService . createTemplate ( imageReference ) . catch ( ( error ) => {
245+ logger . error ( "Shadow compute template creation failed" , {
246+ id : deploymentFriendlyId ,
247+ imageReference,
248+ error : error instanceof Error ? error . message : String ( error ) ,
249+ } ) ;
250+ } ) ;
251+ }
251252}
252253
253254type ExecutePushToRegistryOptions = {
0 commit comments