44 packetRequiresOffloading ,
55 QueueOptions ,
66 SemanticInternalAttributes ,
7+ TaskRunError ,
8+ taskRunErrorEnhancer ,
9+ taskRunErrorToString ,
710 TriggerTaskRequestBody ,
811} from "@trigger.dev/core/v3" ;
912import {
@@ -164,10 +167,10 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
164167 index : options . batchIndex ?? 0 ,
165168 }
166169 : undefined ,
167- environmentId : environment . id ,
168170 projectId : environment . projectId ,
169171 organizationId : environment . organizationId ,
170172 tx : this . _prisma ,
173+ releaseConcurrency : body . options ?. releaseConcurrency ,
171174 } ) ;
172175 }
173176 ) ;
@@ -271,7 +274,7 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
271274 immediate : true ,
272275 } ,
273276 async ( event , traceContext , traceparent ) => {
274- const run = await autoIncrementCounter . incrementInTransaction (
277+ const result = await autoIncrementCounter . incrementInTransaction (
275278 `v3-run:${ environment . id } :${ taskId } ` ,
276279 async ( num , tx ) => {
277280 const lockedToBackgroundWorker = body . options ?. lockToVersion
@@ -370,11 +373,18 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
370373 : undefined ,
371374 machine : body . options ?. machine ,
372375 priorityMs : body . options ?. priority ? body . options . priority * 1_000 : undefined ,
376+ releaseConcurrency : body . options ?. releaseConcurrency ,
373377 } ,
374378 this . _prisma
375379 ) ;
376380
377- return { run : taskRun , isCached : false } ;
381+ const error = taskRun . error ? TaskRunError . parse ( taskRun . error ) : undefined ;
382+
383+ if ( error ) {
384+ event . failWithError ( error ) ;
385+ }
386+
387+ return { run : taskRun , error, isCached : false } ;
378388 } ,
379389 async ( _ , tx ) => {
380390 const counter = await tx . taskRunNumberCounter . findFirst ( {
@@ -390,7 +400,13 @@ export class TriggerTaskServiceV2 extends WithRunEngine {
390400 this . _prisma
391401 ) ;
392402
393- return run ;
403+ if ( result ?. error ) {
404+ throw new ServiceValidationError (
405+ taskRunErrorToString ( taskRunErrorEnhancer ( result . error ) )
406+ ) ;
407+ }
408+
409+ return result ;
394410 }
395411 ) ;
396412 } catch ( error ) {
0 commit comments