@@ -34,7 +34,6 @@ import { IdempotencyKeyConcern } from "../concerns/idempotencyKeys.server";
3434import type {
3535 PayloadProcessor ,
3636 QueueManager ,
37- RunNumberIncrementer ,
3837 TraceEventConcern ,
3938 TriggerRacepoints ,
4039 TriggerRacepointSystem ,
@@ -54,7 +53,6 @@ export class RunEngineTriggerTaskService {
5453 private readonly validator : TriggerTaskValidator ;
5554 private readonly payloadProcessor : PayloadProcessor ;
5655 private readonly idempotencyKeyConcern : IdempotencyKeyConcern ;
57- private readonly runNumberIncrementer : RunNumberIncrementer ;
5856 private readonly prisma : PrismaClientOrTransaction ;
5957 private readonly engine : RunEngine ;
6058 private readonly tracer : Tracer ;
@@ -69,7 +67,6 @@ export class RunEngineTriggerTaskService {
6967 validator : TriggerTaskValidator ;
7068 payloadProcessor : PayloadProcessor ;
7169 idempotencyKeyConcern : IdempotencyKeyConcern ;
72- runNumberIncrementer : RunNumberIncrementer ;
7370 traceEventConcern : TraceEventConcern ;
7471 tracer : Tracer ;
7572 metadataMaximumSize : number ;
@@ -81,7 +78,6 @@ export class RunEngineTriggerTaskService {
8178 this . validator = opts . validator ;
8279 this . payloadProcessor = opts . payloadProcessor ;
8380 this . idempotencyKeyConcern = opts . idempotencyKeyConcern ;
84- this . runNumberIncrementer = opts . runNumberIncrementer ;
8581 this . tracer = opts . tracer ;
8682 this . traceEventConcern = opts . traceEventConcern ;
8783 this . metadataMaximumSize = opts . metadataMaximumSize ;
@@ -271,97 +267,91 @@ export class RunEngineTriggerTaskService {
271267 triggerRequest ,
272268 parentRun ?. taskEventStore ,
273269 async ( event , store ) => {
274- const result = await this . runNumberIncrementer . incrementRunNumber (
275- triggerRequest ,
276- async ( num ) => {
277- event . setAttribute ( "queueName" , queueName ) ;
278- span . setAttribute ( "queueName" , queueName ) ;
279- event . setAttribute ( "runId" , runFriendlyId ) ;
280- span . setAttribute ( "runId" , runFriendlyId ) ;
281-
282- const payloadPacket = await this . payloadProcessor . process ( triggerRequest ) ;
283-
284- const taskRun = await this . engine . trigger (
285- {
286- number : num ,
287- friendlyId : runFriendlyId ,
288- environment : environment ,
289- idempotencyKey,
290- idempotencyKeyExpiresAt : idempotencyKey ? idempotencyKeyExpiresAt : undefined ,
291- taskIdentifier : taskId ,
292- payload : payloadPacket . data ?? "" ,
293- payloadType : payloadPacket . dataType ,
294- context : body . context ,
295- traceContext : this . #propagateExternalTraceContext(
296- event . traceContext ,
297- parentRun ?. traceContext ,
298- event . traceparent ?. spanId
299- ) ,
300- traceId : event . traceId ,
301- spanId : event . spanId ,
302- parentSpanId :
303- options . parentAsLinkType === "replay" ? undefined : event . traceparent ?. spanId ,
304- replayedFromTaskRunFriendlyId : options . replayedFromTaskRunFriendlyId ,
305- lockedToVersionId : lockedToBackgroundWorker ?. id ,
306- taskVersion : lockedToBackgroundWorker ?. version ,
307- sdkVersion : lockedToBackgroundWorker ?. sdkVersion ,
308- cliVersion : lockedToBackgroundWorker ?. cliVersion ,
309- concurrencyKey : body . options ?. concurrencyKey ,
310- queue : queueName ,
311- lockedQueueId,
312- workerQueue,
313- isTest : body . options ?. test ?? false ,
314- delayUntil,
315- queuedAt : delayUntil ? undefined : new Date ( ) ,
316- maxAttempts : body . options ?. maxAttempts ,
317- taskEventStore : store ,
318- ttl,
319- tags,
320- oneTimeUseToken : options . oneTimeUseToken ,
321- parentTaskRunId : parentRun ?. id ,
322- rootTaskRunId : parentRun ?. rootTaskRunId ?? parentRun ?. id ,
323- batch : options ?. batchId
324- ? {
325- id : options . batchId ,
326- index : options . batchIndex ?? 0 ,
327- }
328- : undefined ,
329- resumeParentOnCompletion : body . options ?. resumeParentOnCompletion ,
330- depth,
331- metadata : metadataPacket ?. data ,
332- metadataType : metadataPacket ?. dataType ,
333- seedMetadata : metadataPacket ?. data ,
334- seedMetadataType : metadataPacket ?. dataType ,
335- maxDurationInSeconds : body . options ?. maxDuration
336- ? clampMaxDuration ( body . options . maxDuration )
337- : undefined ,
338- machine : body . options ?. machine ,
339- priorityMs : body . options ?. priority ? body . options . priority * 1_000 : undefined ,
340- queueTimestamp :
341- options . queueTimestamp ??
342- ( parentRun && body . options ?. resumeParentOnCompletion
343- ? parentRun . queueTimestamp ?? undefined
344- : undefined ) ,
345- scheduleId : options . scheduleId ,
346- scheduleInstanceId : options . scheduleInstanceId ,
347- createdAt : options . overrideCreatedAt ,
348- bulkActionId : body . options ?. bulkActionId ,
349- planType,
350- realtimeStreamsVersion : options . realtimeStreamsVersion ,
351- } ,
352- this . prisma
353- ) ;
354-
355- const error = taskRun . error ? TaskRunError . parse ( taskRun . error ) : undefined ;
356-
357- if ( error ) {
358- event . failWithError ( error ) ;
359- }
360-
361- return { run : taskRun , error, isCached : false } ;
362- }
270+ event . setAttribute ( "queueName" , queueName ) ;
271+ span . setAttribute ( "queueName" , queueName ) ;
272+ event . setAttribute ( "runId" , runFriendlyId ) ;
273+ span . setAttribute ( "runId" , runFriendlyId ) ;
274+
275+ const payloadPacket = await this . payloadProcessor . process ( triggerRequest ) ;
276+
277+ const taskRun = await this . engine . trigger (
278+ {
279+ friendlyId : runFriendlyId ,
280+ environment : environment ,
281+ idempotencyKey,
282+ idempotencyKeyExpiresAt : idempotencyKey ? idempotencyKeyExpiresAt : undefined ,
283+ taskIdentifier : taskId ,
284+ payload : payloadPacket . data ?? "" ,
285+ payloadType : payloadPacket . dataType ,
286+ context : body . context ,
287+ traceContext : this . #propagateExternalTraceContext(
288+ event . traceContext ,
289+ parentRun ?. traceContext ,
290+ event . traceparent ?. spanId
291+ ) ,
292+ traceId : event . traceId ,
293+ spanId : event . spanId ,
294+ parentSpanId :
295+ options . parentAsLinkType === "replay" ? undefined : event . traceparent ?. spanId ,
296+ replayedFromTaskRunFriendlyId : options . replayedFromTaskRunFriendlyId ,
297+ lockedToVersionId : lockedToBackgroundWorker ?. id ,
298+ taskVersion : lockedToBackgroundWorker ?. version ,
299+ sdkVersion : lockedToBackgroundWorker ?. sdkVersion ,
300+ cliVersion : lockedToBackgroundWorker ?. cliVersion ,
301+ concurrencyKey : body . options ?. concurrencyKey ,
302+ queue : queueName ,
303+ lockedQueueId,
304+ workerQueue,
305+ isTest : body . options ?. test ?? false ,
306+ delayUntil,
307+ queuedAt : delayUntil ? undefined : new Date ( ) ,
308+ maxAttempts : body . options ?. maxAttempts ,
309+ taskEventStore : store ,
310+ ttl,
311+ tags,
312+ oneTimeUseToken : options . oneTimeUseToken ,
313+ parentTaskRunId : parentRun ?. id ,
314+ rootTaskRunId : parentRun ?. rootTaskRunId ?? parentRun ?. id ,
315+ batch : options ?. batchId
316+ ? {
317+ id : options . batchId ,
318+ index : options . batchIndex ?? 0 ,
319+ }
320+ : undefined ,
321+ resumeParentOnCompletion : body . options ?. resumeParentOnCompletion ,
322+ depth,
323+ metadata : metadataPacket ?. data ,
324+ metadataType : metadataPacket ?. dataType ,
325+ seedMetadata : metadataPacket ?. data ,
326+ seedMetadataType : metadataPacket ?. dataType ,
327+ maxDurationInSeconds : body . options ?. maxDuration
328+ ? clampMaxDuration ( body . options . maxDuration )
329+ : undefined ,
330+ machine : body . options ?. machine ,
331+ priorityMs : body . options ?. priority ? body . options . priority * 1_000 : undefined ,
332+ queueTimestamp :
333+ options . queueTimestamp ??
334+ ( parentRun && body . options ?. resumeParentOnCompletion
335+ ? parentRun . queueTimestamp ?? undefined
336+ : undefined ) ,
337+ scheduleId : options . scheduleId ,
338+ scheduleInstanceId : options . scheduleInstanceId ,
339+ createdAt : options . overrideCreatedAt ,
340+ bulkActionId : body . options ?. bulkActionId ,
341+ planType,
342+ realtimeStreamsVersion : options . realtimeStreamsVersion ,
343+ } ,
344+ this . prisma
363345 ) ;
364346
347+ const error = taskRun . error ? TaskRunError . parse ( taskRun . error ) : undefined ;
348+
349+ if ( error ) {
350+ event . failWithError ( error ) ;
351+ }
352+
353+ const result = { run : taskRun , error, isCached : false } ;
354+
365355 if ( result ?. error ) {
366356 throw new ServiceValidationError (
367357 taskRunErrorToString ( taskRunErrorEnhancer ( result . error ) )
0 commit comments