@@ -196,10 +196,8 @@ export class DeploymentService extends BaseService {
196196 friendlyId : string ,
197197 data ?: Partial < Pick < WorkerDeployment , "canceledReason" > >
198198 ) {
199- const validateDeployment = (
200- deployment : Pick < WorkerDeployment , "id" | "status" | "shortCode" > & {
201- environment : { project : { externalRef : string } } ;
202- }
199+ const validateDeployment = < T extends Pick < WorkerDeployment , "id" | "status" > > (
200+ deployment : T
203201 ) => {
204202 if ( FINAL_DEPLOYMENT_STATUSES . includes ( deployment . status ) ) {
205203 logger . warn ( "Attempted cancelling deployment in a final state" , {
@@ -211,11 +209,7 @@ export class DeploymentService extends BaseService {
211209 return okAsync ( deployment ) ;
212210 } ;
213211
214- const cancelDeployment = (
215- deployment : Pick < WorkerDeployment , "id" | "shortCode" > & {
216- environment : { project : { externalRef : string } } ;
217- }
218- ) =>
212+ const cancelDeployment = < T extends Pick < WorkerDeployment , "id" > > ( deployment : T ) =>
219213 fromPromise (
220214 this . _prisma . workerDeployment . updateMany ( {
221215 where : {
@@ -252,8 +246,21 @@ export class DeploymentService extends BaseService {
252246 . andThen ( validateDeployment )
253247 . andThen ( cancelDeployment )
254248 . andTee ( ( { deployment } ) =>
255- this . #recordCanceledTelemetry( deployment . id ) . orTee ( ( error ) => {
256- logger . error ( "Failed to record canceled deployment telemetry" , { error } ) ;
249+ recordDeploymentFinished ( {
250+ status : "CANCELED" ,
251+ deployment : {
252+ ...deployment ,
253+ status : "CANCELED" ,
254+ canceledAt : new Date ( ) ,
255+ canceledReason : data ?. canceledReason ?? null ,
256+ } ,
257+ environment : {
258+ organizationId : deployment . environment . project . organizationId ,
259+ projectId : deployment . environment . project . id ,
260+ projectRef : deployment . environment . project . externalRef ,
261+ environmentId : deployment . environment . id ,
262+ environmentType : deployment . environment . type ,
263+ } ,
257264 } )
258265 )
259266 . andTee ( ( { deployment } ) =>
@@ -477,42 +484,6 @@ export class DeploymentService extends BaseService {
477484 ) ;
478485 }
479486
480- // The cancel chain only carries a narrow row selection, so re-fetch the full row
481- #recordCanceledTelemetry( deploymentId : string ) {
482- return fromPromise (
483- this . _prisma . workerDeployment . findFirst ( {
484- where : { id : deploymentId } ,
485- include : {
486- environment : {
487- include : {
488- project : {
489- select : { id : true , organizationId : true , externalRef : true } ,
490- } ,
491- } ,
492- } ,
493- } ,
494- } ) ,
495- ( error ) => ( {
496- type : "other" as const ,
497- cause : error ,
498- } )
499- ) . map ( ( canceled ) => {
500- if ( ! canceled || canceled . status !== "CANCELED" ) return ;
501-
502- recordDeploymentFinished ( {
503- status : "CANCELED" ,
504- deployment : canceled ,
505- environment : {
506- organizationId : canceled . environment . project . organizationId ,
507- projectId : canceled . environment . project . id ,
508- projectRef : canceled . environment . project . externalRef ,
509- environmentId : canceled . environmentId ,
510- environmentType : canceled . environment . type ,
511- } ,
512- } ) ;
513- } ) ;
514- }
515-
516487 private getDeployment ( environmentId : string , friendlyId : string ) {
517488 return fromPromise (
518489 this . _prisma . workerDeployment . findFirst ( {
@@ -523,13 +494,32 @@ export class DeploymentService extends BaseService {
523494 select : {
524495 status : true ,
525496 id : true ,
497+ friendlyId : true ,
498+ version : true ,
499+ type : true ,
500+ createdAt : true ,
501+ startedAt : true ,
502+ installedAt : true ,
503+ builtAt : true ,
504+ deployedAt : true ,
505+ failedAt : true ,
506+ canceledAt : true ,
507+ canceledReason : true ,
508+ errorData : true ,
509+ runtime : true ,
510+ runtimeVersion : true ,
511+ cliVersion : true ,
512+ triggeredVia : true ,
513+ commitSHA : true ,
526514 buildServerMetadata : true ,
527515 imageReference : true ,
528516 shortCode : true ,
529517 environment : {
530518 include : {
531519 project : {
532520 select : {
521+ id : true ,
522+ organizationId : true ,
533523 externalRef : true ,
534524 } ,
535525 } ,
0 commit comments