Skip to content

Commit 90f9829

Browse files
committed
fix(sdk): concurrency reaches every trigger path
The option was silently dropped by the seven single-task and subscribe/wait paths and doubled at four by-id batch sites. A named limit object written inline in a task's concurrency now registers as a declaration instead of losing its caps, and trigger-time limit names must be non-empty strings.
1 parent fca81fb commit 90f9829

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function normalizeTaskConcurrency(
180180
"name" in item &&
181181
typeof item.name === "string"
182182
) {
183+
resourceCatalog.registerConcurrencyLimitMetadata(item);
183184
limits.push(item.name);
184185
} else if (item && typeof item === "object") {
185186
inline.push({ perKey: item.perKey, total: item.total });
@@ -225,6 +226,9 @@ function triggerConcurrencyBody(concurrency: string | string[] | undefined): {
225226
if (limits.length > 2) {
226227
throw new Error("The concurrency option accepts at most two named limits.");
227228
}
229+
if (limits.some((name) => typeof name !== "string" || name.length === 0)) {
230+
throw new Error("The concurrency option takes limit names: non-empty strings.");
231+
}
228232
return { concurrency: limits };
229233
}
230234

@@ -870,7 +874,6 @@ export async function batchTriggerById<TTask extends AnyTask>(
870874
options: {
871875
...triggerQueueBody(item.options?.queue),
872876
...triggerConcurrencyBody(item.options?.concurrency),
873-
...triggerConcurrencyBody(item.options?.concurrency),
874877
concurrencyKey: item.options?.concurrencyKey,
875878
test: taskContext.ctx?.run.isTest,
876879
payloadType: payloadPacket.dataType,
@@ -1132,7 +1135,6 @@ export async function batchTriggerByIdAndWait<TTask extends AnyTask>(
11321135
lockToVersion: taskContext.worker?.version,
11331136
...triggerQueueBody(item.options?.queue),
11341137
...triggerConcurrencyBody(item.options?.concurrency),
1135-
...triggerConcurrencyBody(item.options?.concurrency),
11361138
concurrencyKey: item.options?.concurrencyKey,
11371139
test: taskContext.ctx?.run.isTest,
11381140
payloadType: payloadPacket.dataType,
@@ -1399,7 +1401,6 @@ export async function batchTriggerTasks<TTasks extends readonly AnyTask[]>(
13991401
options: {
14001402
...triggerQueueBody(item.options?.queue),
14011403
...triggerConcurrencyBody(item.options?.concurrency),
1402-
...triggerConcurrencyBody(item.options?.concurrency),
14031404
concurrencyKey: item.options?.concurrencyKey,
14041405
test: taskContext.ctx?.run.isTest,
14051406
payloadType: payloadPacket.dataType,
@@ -1666,7 +1667,6 @@ export async function batchTriggerAndWaitTasks<TTasks extends readonly AnyTask[]
16661667
lockToVersion: taskContext.worker?.version,
16671668
...triggerQueueBody(item.options?.queue),
16681669
...triggerConcurrencyBody(item.options?.concurrency),
1669-
...triggerConcurrencyBody(item.options?.concurrency),
16701670
concurrencyKey: item.options?.concurrencyKey,
16711671
test: taskContext.ctx?.run.isTest,
16721672
payloadType: payloadPacket.dataType,
@@ -2366,6 +2366,7 @@ async function* transformSingleTaskBatchItemsStream<TPayload>(
23662366
payload: payloadPacket.data,
23672367
options: {
23682368
...triggerQueueBody(item.options?.queue, queue),
2369+
...triggerConcurrencyBody(item.options?.concurrency),
23692370
concurrencyKey: item.options?.concurrencyKey,
23702371
test: taskContext.ctx?.run.isTest,
23712372
payloadType: payloadPacket.dataType,
@@ -2426,6 +2427,7 @@ async function* transformSingleTaskBatchItemsStreamForWait<TPayload>(
24262427
options: {
24272428
lockToVersion: taskContext.worker?.version,
24282429
...triggerQueueBody(item.options?.queue, queue),
2430+
...triggerConcurrencyBody(item.options?.concurrency),
24292431
concurrencyKey: item.options?.concurrencyKey,
24302432
test: taskContext.ctx?.run.isTest,
24312433
payloadType: payloadPacket.dataType,
@@ -2476,6 +2478,7 @@ async function trigger_internal<TRunTypes extends AnyRunTypes>(
24762478
payload: triggerPayloadPacket.data,
24772479
options: {
24782480
...triggerQueueBody(options?.queue),
2481+
...triggerConcurrencyBody(options?.concurrency),
24792482
concurrencyKey: options?.concurrencyKey,
24802483
test: taskContext.ctx?.run.isTest,
24812484
payloadType: triggerPayloadPacket.dataType,
@@ -2561,6 +2564,7 @@ async function batchTrigger_internal<TRunTypes extends AnyRunTypes>(
25612564
payload: payloadPacket.data,
25622565
options: {
25632566
...triggerQueueBody(item.options?.queue, queue),
2567+
...triggerConcurrencyBody(item.options?.concurrency),
25642568
concurrencyKey: item.options?.concurrencyKey,
25652569
test: taskContext.ctx?.run.isTest,
25662570
payloadType: payloadPacket.dataType,
@@ -2741,6 +2745,7 @@ async function triggerAndWait_internal<TIdentifier extends string, TPayload, TOu
27412745
options: {
27422746
lockToVersion: taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
27432747
...triggerQueueBody(options?.queue),
2748+
...triggerConcurrencyBody(options?.concurrency),
27442749
concurrencyKey: options?.concurrencyKey,
27452750
test: taskContext.ctx?.run.isTest,
27462751
payloadType: triggerPayloadPacket.dataType,
@@ -2831,6 +2836,7 @@ async function triggerAndSubscribe_internal<TIdentifier extends string, TPayload
28312836
options: {
28322837
lockToVersion: taskContext.worker?.version,
28332838
...triggerQueueBody(options?.queue),
2839+
...triggerConcurrencyBody(options?.concurrency),
28342840
concurrencyKey: options?.concurrencyKey,
28352841
test: taskContext.ctx?.run.isTest,
28362842
payloadType: triggerPayloadPacket.dataType,
@@ -2993,6 +2999,7 @@ async function batchTriggerAndWait_internal<TIdentifier extends string, TPayload
29932999
options: {
29943000
lockToVersion: taskContext.worker?.version,
29953001
...triggerQueueBody(item.options?.queue, queue),
3002+
...triggerConcurrencyBody(item.options?.concurrency),
29963003
concurrencyKey: item.options?.concurrencyKey,
29973004
test: taskContext.ctx?.run.isTest,
29983005
payloadType: payloadPacket.dataType,

0 commit comments

Comments
 (0)