@@ -419,17 +419,14 @@ export class DequeueSystem {
419419 // Pre-generate snapshot ID so we can construct the result without an extra read
420420 const snapshotId = generateInternalId ( ) ;
421421
422- const lockedTaskRun = await prisma . taskRun . update ( {
423- where : {
424- id : runId ,
425- } ,
426- data : {
422+ const lockedTaskRun = await this . $ . runStore . lockRunToWorker (
423+ runId ,
424+ {
427425 lockedAt,
428426 lockedById : result . task . id ,
429427 lockedToVersionId : result . worker . id ,
430428 lockedQueueId : result . queue . id ,
431429 lockedRetryConfig : lockedRetryConfig ?? undefined ,
432- status : "DEQUEUED" ,
433430 startedAt,
434431 baseCostInCents : this . options . machines . baseCostInCents ,
435432 machinePreset : machinePreset . name ,
@@ -438,38 +435,27 @@ export class DequeueSystem {
438435 cliVersion : result . worker . cliVersion ,
439436 maxDurationInSeconds,
440437 maxAttempts : maxAttempts ?? undefined ,
441- executionSnapshots : {
442- create : {
443- id : snapshotId ,
444- engine : "V2" ,
445- executionStatus : "PENDING_EXECUTING" ,
446- description : "Run was dequeued for execution" ,
447- // Map DEQUEUED -> PENDING for backwards compatibility with older runners
448- runStatus : "PENDING" ,
449- attemptNumber : result . run . attemptNumber ?? undefined ,
450- previousSnapshotId : snapshot . id ,
451- environmentId : snapshot . environmentId ,
452- environmentType : snapshot . environmentType ,
453- projectId : snapshot . projectId ,
454- organizationId : snapshot . organizationId ,
455- checkpointId : snapshot . checkpointId ?? undefined ,
456- batchId : snapshot . batchId ?? undefined ,
457- completedWaitpoints : {
458- connect : snapshot . completedWaitpoints . map ( ( w ) => ( { id : w . id } ) ) ,
459- } ,
460- completedWaitpointOrder : snapshot . completedWaitpoints
461- . filter ( ( c ) => c . index !== undefined )
462- . sort ( ( a , b ) => a . index ! - b . index ! )
463- . map ( ( w ) => w . id ) ,
464- workerId,
465- runnerId,
466- } ,
438+ snapshot : {
439+ id : snapshotId ,
440+ previousSnapshotId : snapshot . id ,
441+ attemptNumber : result . run . attemptNumber ?? undefined ,
442+ environmentId : snapshot . environmentId ,
443+ environmentType : snapshot . environmentType ,
444+ projectId : snapshot . projectId ,
445+ organizationId : snapshot . organizationId ,
446+ checkpointId : snapshot . checkpointId ?? undefined ,
447+ batchId : snapshot . batchId ?? undefined ,
448+ completedWaitpointIds : snapshot . completedWaitpoints . map ( ( w ) => w . id ) ,
449+ completedWaitpointOrder : snapshot . completedWaitpoints
450+ . filter ( ( c ) => c . index !== undefined )
451+ . sort ( ( a , b ) => a . index ! - b . index ! )
452+ . map ( ( w ) => w . id ) ,
453+ workerId,
454+ runnerId,
467455 } ,
468456 } ,
469- include : {
470- runtimeEnvironment : true ,
471- } ,
472- } ) ;
457+ prisma
458+ ) ;
473459
474460 this . $ . eventBus . emit ( "runLocked" , {
475461 time : new Date ( ) ,
@@ -741,30 +727,32 @@ export class DequeueSystem {
741727 } ) ;
742728
743729 //mark run as waiting for deploy
744- const run = await prisma . taskRun . update ( {
745- where : { id : runId } ,
746- data : {
747- status : "PENDING_VERSION" ,
730+ const run = await this . $ . runStore . parkPendingVersion (
731+ runId ,
732+ {
748733 statusReason,
749734 } ,
750- select : {
751- id : true ,
752- status : true ,
753- attemptNumber : true ,
754- updatedAt : true ,
755- createdAt : true ,
756- runTags : true ,
757- batchId : true ,
758- runtimeEnvironment : {
759- select : {
760- id : true ,
761- type : true ,
762- projectId : true ,
763- project : { select : { id : true , organizationId : true } } ,
735+ {
736+ select : {
737+ id : true ,
738+ status : true ,
739+ attemptNumber : true ,
740+ updatedAt : true ,
741+ createdAt : true ,
742+ runTags : true ,
743+ batchId : true ,
744+ runtimeEnvironment : {
745+ select : {
746+ id : true ,
747+ type : true ,
748+ projectId : true ,
749+ project : { select : { id : true , organizationId : true } } ,
750+ } ,
764751 } ,
765752 } ,
766753 } ,
767- } ) ;
754+ prisma
755+ ) ;
768756
769757 this . $ . logger . debug ( "RunEngine.dequeueFromWorkerQueue(): Pending version" , {
770758 runId,
0 commit comments