@@ -10,6 +10,7 @@ import { machinePresetFromConfig, machinePresetFromRun } from "../machinePresets
1010import { BaseService , ServiceValidationError } from "./baseService.server" ;
1111import { CrashTaskRunService } from "./crashTaskRun.server" ;
1212import { ExpireEnqueuedRunService } from "./expireEnqueuedRun.server" ;
13+ import { findQueueInEnvironment } from "~/models/taskQueue.server" ;
1314
1415export class CreateTaskRunAttemptService extends BaseService {
1516 public async call ( {
@@ -95,18 +96,18 @@ export class CreateTaskRunAttemptService extends BaseService {
9596 throw new ServiceValidationError ( "Task run is cancelled" , 400 ) ;
9697 }
9798
98- if ( ! taskRun . lockedBy ) {
99+ const lockedBy = taskRun . lockedBy ;
100+
101+ if ( ! lockedBy ) {
99102 throw new ServiceValidationError ( "Task run is not locked" , 400 ) ;
100103 }
101104
102- const queue = await this . _prisma . taskQueue . findUnique ( {
103- where : {
104- runtimeEnvironmentId_name : {
105- runtimeEnvironmentId : environment . id ,
106- name : taskRun . queue ,
107- } ,
108- } ,
109- } ) ;
105+ const queue = await findQueueInEnvironment (
106+ taskRun . queue ,
107+ environment . id ,
108+ lockedBy . id ,
109+ lockedBy
110+ ) ;
110111
111112 if ( ! queue ) {
112113 throw new ServiceValidationError ( "Queue not found" , 404 ) ;
@@ -121,7 +122,7 @@ export class CreateTaskRunAttemptService extends BaseService {
121122 if ( nextAttemptNumber > MAX_TASK_RUN_ATTEMPTS ) {
122123 const service = new CrashTaskRunService ( this . _prisma ) ;
123124 await service . call ( taskRun . id , {
124- reason : taskRun . lockedBy . worker . supportsLazyAttempts
125+ reason : lockedBy . worker . supportsLazyAttempts
125126 ? "Max attempts reached."
126127 : "Max attempts reached. Please upgrade your CLI and SDK." ,
127128 } ) ;
@@ -136,8 +137,8 @@ export class CreateTaskRunAttemptService extends BaseService {
136137 friendlyId : generateFriendlyId ( "attempt" ) ,
137138 taskRunId : taskRun . id ,
138139 startedAt : new Date ( ) ,
139- backgroundWorkerId : taskRun . lockedBy ! . worker . id ,
140- backgroundWorkerTaskId : taskRun . lockedBy ! . id ,
140+ backgroundWorkerId : lockedBy . worker . id ,
141+ backgroundWorkerTaskId : lockedBy . id ,
141142 status : setToExecuting ? "EXECUTING" : "PENDING" ,
142143 queueId : queue . id ,
143144 runtimeEnvironmentId : environment . id ,
@@ -174,8 +175,7 @@ export class CreateTaskRunAttemptService extends BaseService {
174175 }
175176
176177 const machinePreset =
177- machinePresetFromRun ( taskRun ) ??
178- machinePresetFromConfig ( taskRun . lockedBy . machineConfig ?? { } ) ;
178+ machinePresetFromRun ( taskRun ) ?? machinePresetFromConfig ( lockedBy . machineConfig ?? { } ) ;
179179
180180 const metadata = await parsePacket ( {
181181 data : taskRun . metadata ?? undefined ,
@@ -184,16 +184,16 @@ export class CreateTaskRunAttemptService extends BaseService {
184184
185185 const execution : TaskRunExecution = {
186186 task : {
187- id : taskRun . lockedBy . slug ,
188- filePath : taskRun . lockedBy . filePath ,
189- exportName : taskRun . lockedBy . exportName ,
187+ id : lockedBy . slug ,
188+ filePath : lockedBy . filePath ,
189+ exportName : lockedBy . exportName ,
190190 } ,
191191 attempt : {
192192 id : taskRunAttempt . friendlyId ,
193193 number : taskRunAttempt . number ,
194194 startedAt : taskRunAttempt . startedAt ?? taskRunAttempt . createdAt ,
195- backgroundWorkerId : taskRun . lockedBy . worker . id ,
196- backgroundWorkerTaskId : taskRun . lockedBy . id ,
195+ backgroundWorkerId : lockedBy . worker . id ,
196+ backgroundWorkerTaskId : lockedBy . id ,
197197 status : "EXECUTING" as const ,
198198 } ,
199199 run : {
@@ -210,7 +210,7 @@ export class CreateTaskRunAttemptService extends BaseService {
210210 costInCents : taskRun . costInCents ,
211211 baseCostInCents : taskRun . baseCostInCents ,
212212 maxAttempts : taskRun . maxAttempts ?? undefined ,
213- version : taskRun . lockedBy . worker . version ,
213+ version : lockedBy . worker . version ,
214214 metadata,
215215 maxDuration : taskRun . maxDurationInSeconds ?? undefined ,
216216 } ,
0 commit comments