@trigger.dev/sdk 3.3.16 → 4.0.0-v4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/v3/ai.d.ts +23 -0
- package/dist/commonjs/v3/ai.js +50 -0
- package/dist/commonjs/v3/ai.js.map +1 -0
- package/dist/commonjs/v3/auth.d.ts +4 -3
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/hooks.d.ts +22 -0
- package/dist/commonjs/v3/hooks.js +65 -0
- package/dist/commonjs/v3/hooks.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +3 -1
- package/dist/commonjs/v3/index.js +4 -1
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/locals.d.ts +3 -0
- package/dist/commonjs/v3/locals.js +6 -0
- package/dist/commonjs/v3/locals.js.map +1 -0
- package/dist/commonjs/v3/queues.d.ts +61 -0
- package/dist/commonjs/v3/queues.js +137 -0
- package/dist/commonjs/v3/queues.js.map +1 -0
- package/dist/commonjs/v3/retry.js +10 -7
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +40 -40
- package/dist/commonjs/v3/schedules/index.js +1 -1
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +7 -6
- package/dist/commonjs/v3/shared.js +192 -176
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +12 -0
- package/dist/commonjs/v3/tasks.js +11 -0
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +208 -3
- package/dist/commonjs/v3/wait.js +407 -7
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +23 -0
- package/dist/esm/v3/ai.js +47 -0
- package/dist/esm/v3/ai.js.map +1 -0
- package/dist/esm/v3/auth.d.ts +4 -3
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/hooks.d.ts +22 -0
- package/dist/esm/v3/hooks.js +54 -0
- package/dist/esm/v3/hooks.js.map +1 -0
- package/dist/esm/v3/index.d.ts +3 -1
- package/dist/esm/v3/index.js +3 -1
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/locals.d.ts +3 -0
- package/dist/esm/v3/locals.js +3 -0
- package/dist/esm/v3/locals.js.map +1 -0
- package/dist/esm/v3/queues.d.ts +61 -0
- package/dist/esm/v3/queues.js +131 -0
- package/dist/esm/v3/queues.js.map +1 -0
- package/dist/esm/v3/retry.js +11 -8
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +39 -39
- package/dist/esm/v3/schedules/index.js +2 -2
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +7 -6
- package/dist/esm/v3/shared.js +193 -177
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +12 -0
- package/dist/esm/v3/tasks.js +11 -0
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +208 -3
- package/dist/esm/v3/wait.js +406 -7
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +36 -17
- package/dist/commonjs/apiClient.d.ts +0 -727
- package/dist/commonjs/apiClient.js +0 -692
- package/dist/commonjs/apiClient.js.map +0 -1
- package/dist/commonjs/concurrencyLimit.d.ts +0 -10
- package/dist/commonjs/concurrencyLimit.js +0 -17
- package/dist/commonjs/concurrencyLimit.js.map +0 -1
- package/dist/commonjs/errors.d.ts +0 -66
- package/dist/commonjs/errors.js +0 -109
- package/dist/commonjs/errors.js.map +0 -1
- package/dist/commonjs/httpEndpoint.d.ts +0 -87
- package/dist/commonjs/httpEndpoint.js +0 -130
- package/dist/commonjs/httpEndpoint.js.map +0 -1
- package/dist/commonjs/index.d.ts +0 -23
- package/dist/commonjs/index.js +0 -55
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/integrations.d.ts +0 -11
- package/dist/commonjs/integrations.js +0 -3
- package/dist/commonjs/integrations.js.map +0 -1
- package/dist/commonjs/io.d.ts +0 -441
- package/dist/commonjs/io.js +0 -1165
- package/dist/commonjs/io.js.map +0 -1
- package/dist/commonjs/ioWithIntegrations.d.ts +0 -4
- package/dist/commonjs/ioWithIntegrations.js +0 -32
- package/dist/commonjs/ioWithIntegrations.js.map +0 -1
- package/dist/commonjs/job.d.ts +0 -96
- package/dist/commonjs/job.js +0 -210
- package/dist/commonjs/job.js.map +0 -1
- package/dist/commonjs/retry.d.ts +0 -20
- package/dist/commonjs/retry.js +0 -22
- package/dist/commonjs/retry.js.map +0 -1
- package/dist/commonjs/runLocalStorage.d.ts +0 -8
- package/dist/commonjs/runLocalStorage.js +0 -6
- package/dist/commonjs/runLocalStorage.js.map +0 -1
- package/dist/commonjs/security.d.ts +0 -18
- package/dist/commonjs/security.js +0 -41
- package/dist/commonjs/security.js.map +0 -1
- package/dist/commonjs/status.d.ts +0 -19
- package/dist/commonjs/status.js +0 -38
- package/dist/commonjs/status.js.map +0 -1
- package/dist/commonjs/store/keyValueStore.d.ts +0 -17
- package/dist/commonjs/store/keyValueStore.js +0 -138
- package/dist/commonjs/store/keyValueStore.js.map +0 -1
- package/dist/commonjs/store/keyValueStoreClient.d.ts +0 -19
- package/dist/commonjs/store/keyValueStoreClient.js +0 -65
- package/dist/commonjs/store/keyValueStoreClient.js.map +0 -1
- package/dist/commonjs/triggerClient.d.ts +0 -290
- package/dist/commonjs/triggerClient.js +0 -1366
- package/dist/commonjs/triggerClient.js.map +0 -1
- package/dist/commonjs/triggers/dynamic.d.ts +0 -56
- package/dist/commonjs/triggers/dynamic.js +0 -97
- package/dist/commonjs/triggers/dynamic.js.map +0 -1
- package/dist/commonjs/triggers/eventTrigger.d.ts +0 -58
- package/dist/commonjs/triggers/eventTrigger.js +0 -69
- package/dist/commonjs/triggers/eventTrigger.js.map +0 -1
- package/dist/commonjs/triggers/externalSource.d.ts +0 -148
- package/dist/commonjs/triggers/externalSource.js +0 -106
- package/dist/commonjs/triggers/externalSource.js.map +0 -1
- package/dist/commonjs/triggers/invokeTrigger.d.ts +0 -39
- package/dist/commonjs/triggers/invokeTrigger.js +0 -58
- package/dist/commonjs/triggers/invokeTrigger.js.map +0 -1
- package/dist/commonjs/triggers/notifications.d.ts +0 -111
- package/dist/commonjs/triggers/notifications.js +0 -101
- package/dist/commonjs/triggers/notifications.js.map +0 -1
- package/dist/commonjs/triggers/scheduled.d.ts +0 -145
- package/dist/commonjs/triggers/scheduled.js +0 -208
- package/dist/commonjs/triggers/scheduled.js.map +0 -1
- package/dist/commonjs/triggers/webhook.d.ts +0 -143
- package/dist/commonjs/triggers/webhook.js +0 -133
- package/dist/commonjs/triggers/webhook.js.map +0 -1
- package/dist/commonjs/typed-emitter.d.ts +0 -37
- package/dist/commonjs/typed-emitter.js +0 -3
- package/dist/commonjs/typed-emitter.js.map +0 -1
- package/dist/commonjs/types.d.ts +0 -204
- package/dist/commonjs/types.js +0 -23
- package/dist/commonjs/types.js.map +0 -1
- package/dist/commonjs/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/commonjs/utils/formatSchemaErrors.js +0 -10
- package/dist/commonjs/utils/formatSchemaErrors.js.map +0 -1
- package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/commonjs/utils/typedAsyncLocalStorage.js +0 -18
- package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/commonjs/utils.d.ts +0 -1
- package/dist/commonjs/utils.js +0 -11
- package/dist/commonjs/utils.js.map +0 -1
- package/dist/esm/apiClient.d.ts +0 -727
- package/dist/esm/apiClient.js +0 -687
- package/dist/esm/apiClient.js.map +0 -1
- package/dist/esm/concurrencyLimit.d.ts +0 -10
- package/dist/esm/concurrencyLimit.js +0 -13
- package/dist/esm/concurrencyLimit.js.map +0 -1
- package/dist/esm/errors.d.ts +0 -66
- package/dist/esm/errors.js +0 -95
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/httpEndpoint.d.ts +0 -87
- package/dist/esm/httpEndpoint.js +0 -125
- package/dist/esm/httpEndpoint.js.map +0 -1
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -35
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/integrations.d.ts +0 -11
- package/dist/esm/integrations.js +0 -2
- package/dist/esm/integrations.js.map +0 -1
- package/dist/esm/io.d.ts +0 -441
- package/dist/esm/io.js +0 -1159
- package/dist/esm/io.js.map +0 -1
- package/dist/esm/ioWithIntegrations.d.ts +0 -4
- package/dist/esm/ioWithIntegrations.js +0 -29
- package/dist/esm/ioWithIntegrations.js.map +0 -1
- package/dist/esm/job.d.ts +0 -96
- package/dist/esm/job.js +0 -206
- package/dist/esm/job.js.map +0 -1
- package/dist/esm/retry.d.ts +0 -20
- package/dist/esm/retry.js +0 -19
- package/dist/esm/retry.js.map +0 -1
- package/dist/esm/runLocalStorage.d.ts +0 -8
- package/dist/esm/runLocalStorage.js +0 -3
- package/dist/esm/runLocalStorage.js.map +0 -1
- package/dist/esm/security.d.ts +0 -18
- package/dist/esm/security.js +0 -34
- package/dist/esm/security.js.map +0 -1
- package/dist/esm/status.d.ts +0 -19
- package/dist/esm/status.js +0 -34
- package/dist/esm/status.js.map +0 -1
- package/dist/esm/store/keyValueStore.d.ts +0 -17
- package/dist/esm/store/keyValueStore.js +0 -134
- package/dist/esm/store/keyValueStore.js.map +0 -1
- package/dist/esm/store/keyValueStoreClient.d.ts +0 -19
- package/dist/esm/store/keyValueStoreClient.js +0 -61
- package/dist/esm/store/keyValueStoreClient.js.map +0 -1
- package/dist/esm/triggerClient.d.ts +0 -288
- package/dist/esm/triggerClient.js +0 -1359
- package/dist/esm/triggerClient.js.map +0 -1
- package/dist/esm/triggers/dynamic.d.ts +0 -56
- package/dist/esm/triggers/dynamic.js +0 -93
- package/dist/esm/triggers/dynamic.js.map +0 -1
- package/dist/esm/triggers/eventTrigger.d.ts +0 -58
- package/dist/esm/triggers/eventTrigger.js +0 -64
- package/dist/esm/triggers/eventTrigger.js.map +0 -1
- package/dist/esm/triggers/externalSource.d.ts +0 -148
- package/dist/esm/triggers/externalSource.js +0 -100
- package/dist/esm/triggers/externalSource.js.map +0 -1
- package/dist/esm/triggers/invokeTrigger.d.ts +0 -39
- package/dist/esm/triggers/invokeTrigger.js +0 -53
- package/dist/esm/triggers/invokeTrigger.js.map +0 -1
- package/dist/esm/triggers/notifications.d.ts +0 -111
- package/dist/esm/triggers/notifications.js +0 -94
- package/dist/esm/triggers/notifications.js.map +0 -1
- package/dist/esm/triggers/scheduled.d.ts +0 -145
- package/dist/esm/triggers/scheduled.js +0 -197
- package/dist/esm/triggers/scheduled.js.map +0 -1
- package/dist/esm/triggers/webhook.d.ts +0 -143
- package/dist/esm/triggers/webhook.js +0 -128
- package/dist/esm/triggers/webhook.js.map +0 -1
- package/dist/esm/typed-emitter.d.ts +0 -37
- package/dist/esm/typed-emitter.js +0 -2
- package/dist/esm/typed-emitter.js.map +0 -1
- package/dist/esm/types.d.ts +0 -204
- package/dist/esm/types.js +0 -19
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/esm/utils/formatSchemaErrors.js +0 -7
- package/dist/esm/utils/formatSchemaErrors.js.map +0 -1
- package/dist/esm/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/esm/utils/typedAsyncLocalStorage.js +0 -14
- package/dist/esm/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -8
- package/dist/esm/utils.js.map +0 -1
package/dist/esm/v3/shared.js
CHANGED
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
import { SpanKind } from "@opentelemetry/api";
|
|
2
|
-
import { accessoryAttributes, apiClientManager, conditionallyImportPacket, convertToolParametersToSchema, createErrorTaskError, defaultRetryOptions, getSchemaParseFn, makeIdempotencyKey, parsePacket, runtime, SemanticInternalAttributes, stringifyIO, SubtaskUnwrapError,
|
|
2
|
+
import { accessoryAttributes, apiClientManager, conditionallyImportPacket, convertToolParametersToSchema, createErrorTaskError, defaultRetryOptions, flattenIdempotencyKey, getEnvVar, getSchemaParseFn, lifecycleHooks, makeIdempotencyKey, parsePacket, resourceCatalog, runtime, SemanticInternalAttributes, stringifyIO, SubtaskUnwrapError, taskContext, TaskRunPromise, } from "@trigger.dev/core/v3";
|
|
3
3
|
import { runs } from "./runs.js";
|
|
4
4
|
import { tracer } from "./tracer.js";
|
|
5
5
|
export { SubtaskUnwrapError, TaskRunPromise };
|
|
6
6
|
export function queue(options) {
|
|
7
|
+
resourceCatalog.registerQueueMetadata(options);
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
options[Symbol.for("trigger.dev/queue")] = true;
|
|
7
10
|
return options;
|
|
8
11
|
}
|
|
9
12
|
export function createTask(params) {
|
|
10
|
-
const customQueue = params.queue
|
|
11
|
-
? queue({
|
|
12
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
13
|
-
...params.queue,
|
|
14
|
-
})
|
|
15
|
-
: undefined;
|
|
16
13
|
const task = {
|
|
17
14
|
id: params.id,
|
|
18
15
|
description: params.description,
|
|
19
16
|
trigger: async (payload, options) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
23
|
-
: `trigger()`, params.id, payload, undefined, {
|
|
24
|
-
queue: customQueue,
|
|
17
|
+
return await trigger_internal("trigger()", params.id, payload, undefined, {
|
|
18
|
+
queue: params.queue?.name,
|
|
25
19
|
...options,
|
|
26
20
|
});
|
|
27
21
|
},
|
|
28
22
|
batchTrigger: async (items, options) => {
|
|
29
|
-
|
|
30
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
31
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
32
|
-
: `batchTrigger()`, params.id, items, options, undefined, undefined, customQueue);
|
|
23
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, undefined, undefined, params.queue?.name);
|
|
33
24
|
},
|
|
34
25
|
triggerAndWait: (payload, options) => {
|
|
35
|
-
const taskMetadata = taskCatalog.getTaskManifest(params.id);
|
|
36
26
|
return new TaskRunPromise((resolve, reject) => {
|
|
37
|
-
triggerAndWait_internal(
|
|
38
|
-
|
|
39
|
-
: `triggerAndWait()`, params.id, payload, undefined, {
|
|
40
|
-
queue: customQueue,
|
|
27
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, undefined, {
|
|
28
|
+
queue: params.queue?.name,
|
|
41
29
|
...options,
|
|
42
30
|
})
|
|
43
31
|
.then((result) => {
|
|
@@ -49,13 +37,11 @@ export function createTask(params) {
|
|
|
49
37
|
}, params.id);
|
|
50
38
|
},
|
|
51
39
|
batchTriggerAndWait: async (items, options) => {
|
|
52
|
-
|
|
53
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
54
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
55
|
-
: `batchTriggerAndWait()`, params.id, items, undefined, options, undefined, customQueue);
|
|
40
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, undefined, options, undefined, params.queue?.name);
|
|
56
41
|
},
|
|
57
42
|
};
|
|
58
|
-
|
|
43
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
44
|
+
resourceCatalog.registerTaskMetadata({
|
|
59
45
|
id: params.id,
|
|
60
46
|
description: params.description,
|
|
61
47
|
queue: params.queue,
|
|
@@ -64,19 +50,23 @@ export function createTask(params) {
|
|
|
64
50
|
maxDuration: params.maxDuration,
|
|
65
51
|
fns: {
|
|
66
52
|
run: params.run,
|
|
67
|
-
init: params.init,
|
|
68
|
-
cleanup: params.cleanup,
|
|
69
|
-
middleware: params.middleware,
|
|
70
|
-
handleError: params.handleError,
|
|
71
|
-
onSuccess: params.onSuccess,
|
|
72
|
-
onFailure: params.onFailure,
|
|
73
|
-
onStart: params.onStart,
|
|
74
53
|
},
|
|
75
54
|
});
|
|
55
|
+
const queue = params.queue;
|
|
56
|
+
if (queue && typeof queue.name === "string") {
|
|
57
|
+
resourceCatalog.registerQueueMetadata({
|
|
58
|
+
name: queue.name,
|
|
59
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
60
|
+
releaseConcurrencyOnWaitpoint: queue.releaseConcurrencyOnWaitpoint,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
76
63
|
// @ts-expect-error
|
|
77
64
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
78
65
|
return task;
|
|
79
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated use ai.tool() instead
|
|
69
|
+
*/
|
|
80
70
|
export function createToolTask(params) {
|
|
81
71
|
const task = createSchemaTask({
|
|
82
72
|
...params,
|
|
@@ -94,12 +84,6 @@ export function createToolTask(params) {
|
|
|
94
84
|
};
|
|
95
85
|
}
|
|
96
86
|
export function createSchemaTask(params) {
|
|
97
|
-
const customQueue = params.queue
|
|
98
|
-
? queue({
|
|
99
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
100
|
-
...params.queue,
|
|
101
|
-
})
|
|
102
|
-
: undefined;
|
|
103
87
|
const parsePayload = params.schema
|
|
104
88
|
? getSchemaParseFn(params.schema)
|
|
105
89
|
: undefined;
|
|
@@ -108,27 +92,18 @@ export function createSchemaTask(params) {
|
|
|
108
92
|
description: params.description,
|
|
109
93
|
schema: params.schema,
|
|
110
94
|
trigger: async (payload, options, requestOptions) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
114
|
-
: `trigger()`, params.id, payload, parsePayload, {
|
|
115
|
-
queue: customQueue,
|
|
95
|
+
return await trigger_internal("trigger()", params.id, payload, parsePayload, {
|
|
96
|
+
queue: params.queue?.name,
|
|
116
97
|
...options,
|
|
117
98
|
}, requestOptions);
|
|
118
99
|
},
|
|
119
100
|
batchTrigger: async (items, options, requestOptions) => {
|
|
120
|
-
|
|
121
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
122
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
123
|
-
: `batchTrigger()`, params.id, items, options, parsePayload, requestOptions, customQueue);
|
|
101
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, parsePayload, requestOptions, params.queue?.name);
|
|
124
102
|
},
|
|
125
103
|
triggerAndWait: (payload, options) => {
|
|
126
|
-
const taskMetadata = taskCatalog.getTaskManifest(params.id);
|
|
127
104
|
return new TaskRunPromise((resolve, reject) => {
|
|
128
|
-
triggerAndWait_internal(
|
|
129
|
-
|
|
130
|
-
: `triggerAndWait()`, params.id, payload, parsePayload, {
|
|
131
|
-
queue: customQueue,
|
|
105
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, parsePayload, {
|
|
106
|
+
queue: params.queue?.name,
|
|
132
107
|
...options,
|
|
133
108
|
})
|
|
134
109
|
.then((result) => {
|
|
@@ -140,13 +115,11 @@ export function createSchemaTask(params) {
|
|
|
140
115
|
}, params.id);
|
|
141
116
|
},
|
|
142
117
|
batchTriggerAndWait: async (items, options) => {
|
|
143
|
-
|
|
144
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
145
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
146
|
-
: `batchTriggerAndWait()`, params.id, items, parsePayload, options, undefined, customQueue);
|
|
118
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, parsePayload, options, undefined, params.queue?.name);
|
|
147
119
|
},
|
|
148
120
|
};
|
|
149
|
-
|
|
121
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
122
|
+
resourceCatalog.registerTaskMetadata({
|
|
150
123
|
id: params.id,
|
|
151
124
|
description: params.description,
|
|
152
125
|
queue: params.queue,
|
|
@@ -155,16 +128,17 @@ export function createSchemaTask(params) {
|
|
|
155
128
|
maxDuration: params.maxDuration,
|
|
156
129
|
fns: {
|
|
157
130
|
run: params.run,
|
|
158
|
-
init: params.init,
|
|
159
|
-
cleanup: params.cleanup,
|
|
160
|
-
middleware: params.middleware,
|
|
161
|
-
handleError: params.handleError,
|
|
162
|
-
onSuccess: params.onSuccess,
|
|
163
|
-
onFailure: params.onFailure,
|
|
164
|
-
onStart: params.onStart,
|
|
165
131
|
parsePayload,
|
|
166
132
|
},
|
|
167
133
|
});
|
|
134
|
+
const queue = params.queue;
|
|
135
|
+
if (queue && typeof queue.name === "string") {
|
|
136
|
+
resourceCatalog.registerQueueMetadata({
|
|
137
|
+
name: queue.name,
|
|
138
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
139
|
+
releaseConcurrencyOnWaitpoint: queue.releaseConcurrencyOnWaitpoint,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
168
142
|
// @ts-expect-error
|
|
169
143
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
170
144
|
return task;
|
|
@@ -321,38 +295,39 @@ export async function batchTrigger(id, items, options, requestOptions) {
|
|
|
321
295
|
*/
|
|
322
296
|
export async function batchTriggerById(items, options, requestOptions) {
|
|
323
297
|
const apiClient = apiClientManager.clientOrThrow();
|
|
324
|
-
const response = await apiClient.
|
|
325
|
-
items: await Promise.all(items.map(async (item) => {
|
|
326
|
-
const taskMetadata =
|
|
298
|
+
const response = await apiClient.batchTriggerV3({
|
|
299
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
300
|
+
const taskMetadata = resourceCatalog.getTask(item.id);
|
|
327
301
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
328
302
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
329
303
|
: item.payload;
|
|
330
304
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
305
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
331
306
|
return {
|
|
332
307
|
task: item.id,
|
|
333
308
|
payload: payloadPacket.data,
|
|
334
309
|
options: {
|
|
335
|
-
queue: item.options?.queue,
|
|
310
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
336
311
|
concurrencyKey: item.options?.concurrencyKey,
|
|
337
312
|
test: taskContext.ctx?.run.isTest,
|
|
338
313
|
payloadType: payloadPacket.dataType,
|
|
339
|
-
idempotencyKey: await makeIdempotencyKey(item.options?.idempotencyKey),
|
|
340
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
341
314
|
delay: item.options?.delay,
|
|
342
315
|
ttl: item.options?.ttl,
|
|
343
316
|
tags: item.options?.tags,
|
|
344
317
|
maxAttempts: item.options?.maxAttempts,
|
|
345
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
346
318
|
metadata: item.options?.metadata,
|
|
347
319
|
maxDuration: item.options?.maxDuration,
|
|
320
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
321
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
348
322
|
machine: item.options?.machine,
|
|
323
|
+
priority: item.options?.priority,
|
|
324
|
+
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
349
325
|
},
|
|
350
326
|
};
|
|
351
327
|
})),
|
|
328
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
352
329
|
}, {
|
|
353
330
|
spanParentAsLink: true,
|
|
354
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
355
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
356
331
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
357
332
|
}, {
|
|
358
333
|
name: "batch.trigger()",
|
|
@@ -363,17 +338,8 @@ export async function batchTriggerById(items, options, requestOptions) {
|
|
|
363
338
|
if ("id" in body && typeof body.id === "string") {
|
|
364
339
|
span.setAttribute("batchId", body.id);
|
|
365
340
|
}
|
|
366
|
-
if ("
|
|
367
|
-
span.setAttribute("runCount", body.
|
|
368
|
-
}
|
|
369
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
370
|
-
if (body.isCached) {
|
|
371
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
372
|
-
}
|
|
373
|
-
span.setAttribute("isCached", body.isCached);
|
|
374
|
-
}
|
|
375
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
376
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
341
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
342
|
+
span.setAttribute("runCount", body.runCount);
|
|
377
343
|
}
|
|
378
344
|
}
|
|
379
345
|
},
|
|
@@ -381,9 +347,7 @@ export async function batchTriggerById(items, options, requestOptions) {
|
|
|
381
347
|
});
|
|
382
348
|
const handle = {
|
|
383
349
|
batchId: response.id,
|
|
384
|
-
|
|
385
|
-
idempotencyKey: response.idempotencyKey,
|
|
386
|
-
runs: response.runs,
|
|
350
|
+
runCount: response.runCount,
|
|
387
351
|
publicAccessToken: response.publicAccessToken,
|
|
388
352
|
};
|
|
389
353
|
return handle;
|
|
@@ -472,19 +436,20 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
472
436
|
}
|
|
473
437
|
const apiClient = apiClientManager.clientOrThrow();
|
|
474
438
|
return await tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
475
|
-
const response = await apiClient.
|
|
476
|
-
items: await Promise.all(items.map(async (item) => {
|
|
477
|
-
const taskMetadata =
|
|
439
|
+
const response = await apiClient.batchTriggerV3({
|
|
440
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
441
|
+
const taskMetadata = resourceCatalog.getTask(item.id);
|
|
478
442
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
479
443
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
480
444
|
: item.payload;
|
|
481
445
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
446
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
482
447
|
return {
|
|
483
448
|
task: item.id,
|
|
484
449
|
payload: payloadPacket.data,
|
|
485
450
|
options: {
|
|
486
451
|
lockToVersion: taskContext.worker?.version,
|
|
487
|
-
queue: item.options?.queue,
|
|
452
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
488
453
|
concurrencyKey: item.options?.concurrencyKey,
|
|
489
454
|
test: taskContext.ctx?.run.isTest,
|
|
490
455
|
payloadType: payloadPacket.dataType,
|
|
@@ -494,26 +459,24 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
494
459
|
maxAttempts: item.options?.maxAttempts,
|
|
495
460
|
metadata: item.options?.metadata,
|
|
496
461
|
maxDuration: item.options?.maxDuration,
|
|
462
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
463
|
+
batchItemIdempotencyKey,
|
|
464
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
497
465
|
machine: item.options?.machine,
|
|
466
|
+
priority: item.options?.priority,
|
|
498
467
|
},
|
|
499
468
|
};
|
|
500
469
|
})),
|
|
501
|
-
|
|
470
|
+
parentRunId: ctx.run.id,
|
|
471
|
+
resumeParentOnCompletion: true,
|
|
502
472
|
}, {
|
|
503
473
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
504
474
|
}, requestOptions);
|
|
505
475
|
span.setAttribute("batchId", response.id);
|
|
506
|
-
span.setAttribute("runCount", response.
|
|
507
|
-
span.setAttribute("isCached", response.isCached);
|
|
508
|
-
if (response.isCached) {
|
|
509
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
510
|
-
}
|
|
511
|
-
if (response.idempotencyKey) {
|
|
512
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
513
|
-
}
|
|
476
|
+
span.setAttribute("runCount", response.runCount);
|
|
514
477
|
const result = await runtime.waitForBatch({
|
|
515
478
|
id: response.id,
|
|
516
|
-
|
|
479
|
+
runCount: response.runCount,
|
|
517
480
|
ctx,
|
|
518
481
|
});
|
|
519
482
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -607,38 +570,39 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
607
570
|
*/
|
|
608
571
|
export async function batchTriggerTasks(items, options, requestOptions) {
|
|
609
572
|
const apiClient = apiClientManager.clientOrThrow();
|
|
610
|
-
const response = await apiClient.
|
|
611
|
-
items: await Promise.all(items.map(async (item) => {
|
|
612
|
-
const taskMetadata =
|
|
573
|
+
const response = await apiClient.batchTriggerV3({
|
|
574
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
575
|
+
const taskMetadata = resourceCatalog.getTask(item.task.id);
|
|
613
576
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
614
577
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
615
578
|
: item.payload;
|
|
616
579
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
580
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
617
581
|
return {
|
|
618
582
|
task: item.task.id,
|
|
619
583
|
payload: payloadPacket.data,
|
|
620
584
|
options: {
|
|
621
|
-
queue: item.options?.queue,
|
|
585
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
622
586
|
concurrencyKey: item.options?.concurrencyKey,
|
|
623
587
|
test: taskContext.ctx?.run.isTest,
|
|
624
588
|
payloadType: payloadPacket.dataType,
|
|
625
|
-
idempotencyKey: await makeIdempotencyKey(item.options?.idempotencyKey),
|
|
626
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
627
589
|
delay: item.options?.delay,
|
|
628
590
|
ttl: item.options?.ttl,
|
|
629
591
|
tags: item.options?.tags,
|
|
630
592
|
maxAttempts: item.options?.maxAttempts,
|
|
631
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
632
593
|
metadata: item.options?.metadata,
|
|
633
594
|
maxDuration: item.options?.maxDuration,
|
|
595
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
596
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
634
597
|
machine: item.options?.machine,
|
|
598
|
+
priority: item.options?.priority,
|
|
599
|
+
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
635
600
|
},
|
|
636
601
|
};
|
|
637
602
|
})),
|
|
603
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
638
604
|
}, {
|
|
639
605
|
spanParentAsLink: true,
|
|
640
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
641
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
642
606
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
643
607
|
}, {
|
|
644
608
|
name: "batch.triggerByTask()",
|
|
@@ -649,17 +613,8 @@ export async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
649
613
|
if ("id" in body && typeof body.id === "string") {
|
|
650
614
|
span.setAttribute("batchId", body.id);
|
|
651
615
|
}
|
|
652
|
-
if ("
|
|
653
|
-
span.setAttribute("runCount", body.
|
|
654
|
-
}
|
|
655
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
656
|
-
if (body.isCached) {
|
|
657
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
658
|
-
}
|
|
659
|
-
span.setAttribute("isCached", body.isCached);
|
|
660
|
-
}
|
|
661
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
662
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
616
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
617
|
+
span.setAttribute("runCount", body.runCount);
|
|
663
618
|
}
|
|
664
619
|
}
|
|
665
620
|
},
|
|
@@ -667,9 +622,7 @@ export async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
667
622
|
});
|
|
668
623
|
const handle = {
|
|
669
624
|
batchId: response.id,
|
|
670
|
-
|
|
671
|
-
idempotencyKey: response.idempotencyKey,
|
|
672
|
-
runs: response.runs,
|
|
625
|
+
runCount: response.runCount,
|
|
673
626
|
publicAccessToken: response.publicAccessToken,
|
|
674
627
|
};
|
|
675
628
|
return handle;
|
|
@@ -758,19 +711,20 @@ export async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
758
711
|
}
|
|
759
712
|
const apiClient = apiClientManager.clientOrThrow();
|
|
760
713
|
return await tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
761
|
-
const response = await apiClient.
|
|
762
|
-
items: await Promise.all(items.map(async (item) => {
|
|
763
|
-
const taskMetadata =
|
|
714
|
+
const response = await apiClient.batchTriggerV3({
|
|
715
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
716
|
+
const taskMetadata = resourceCatalog.getTask(item.task.id);
|
|
764
717
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
765
718
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
766
719
|
: item.payload;
|
|
767
720
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
721
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
768
722
|
return {
|
|
769
723
|
task: item.task.id,
|
|
770
724
|
payload: payloadPacket.data,
|
|
771
725
|
options: {
|
|
772
726
|
lockToVersion: taskContext.worker?.version,
|
|
773
|
-
queue: item.options?.queue,
|
|
727
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
774
728
|
concurrencyKey: item.options?.concurrencyKey,
|
|
775
729
|
test: taskContext.ctx?.run.isTest,
|
|
776
730
|
payloadType: payloadPacket.dataType,
|
|
@@ -780,26 +734,24 @@ export async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
780
734
|
maxAttempts: item.options?.maxAttempts,
|
|
781
735
|
metadata: item.options?.metadata,
|
|
782
736
|
maxDuration: item.options?.maxDuration,
|
|
737
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
738
|
+
batchItemIdempotencyKey,
|
|
739
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
783
740
|
machine: item.options?.machine,
|
|
741
|
+
priority: item.options?.priority,
|
|
784
742
|
},
|
|
785
743
|
};
|
|
786
744
|
})),
|
|
787
|
-
|
|
745
|
+
parentRunId: ctx.run.id,
|
|
746
|
+
resumeParentOnCompletion: true,
|
|
788
747
|
}, {
|
|
789
748
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
790
749
|
}, requestOptions);
|
|
791
750
|
span.setAttribute("batchId", response.id);
|
|
792
|
-
span.setAttribute("runCount", response.
|
|
793
|
-
span.setAttribute("isCached", response.isCached);
|
|
794
|
-
if (response.isCached) {
|
|
795
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
796
|
-
}
|
|
797
|
-
if (response.idempotencyKey) {
|
|
798
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
799
|
-
}
|
|
751
|
+
span.setAttribute("runCount", response.runCount);
|
|
800
752
|
const result = await runtime.waitForBatch({
|
|
801
753
|
id: response.id,
|
|
802
|
-
|
|
754
|
+
runCount: response.runCount,
|
|
803
755
|
ctx,
|
|
804
756
|
});
|
|
805
757
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -821,7 +773,7 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
821
773
|
const handle = await apiClient.triggerTask(id, {
|
|
822
774
|
payload: payloadPacket.data,
|
|
823
775
|
options: {
|
|
824
|
-
queue: options?.queue,
|
|
776
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
825
777
|
concurrencyKey: options?.concurrencyKey,
|
|
826
778
|
test: taskContext.ctx?.run.isTest,
|
|
827
779
|
payloadType: payloadPacket.dataType,
|
|
@@ -831,10 +783,12 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
831
783
|
ttl: options?.ttl,
|
|
832
784
|
tags: options?.tags,
|
|
833
785
|
maxAttempts: options?.maxAttempts,
|
|
834
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
835
786
|
metadata: options?.metadata,
|
|
836
787
|
maxDuration: options?.maxDuration,
|
|
788
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
837
789
|
machine: options?.machine,
|
|
790
|
+
priority: options?.priority,
|
|
791
|
+
lockToVersion: options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
838
792
|
},
|
|
839
793
|
}, {
|
|
840
794
|
spanParentAsLink: true,
|
|
@@ -855,35 +809,41 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
855
809
|
}
|
|
856
810
|
async function batchTrigger_internal(name, taskIdentifier, items, options, parsePayload, requestOptions, queue) {
|
|
857
811
|
const apiClient = apiClientManager.clientOrThrow();
|
|
858
|
-
const
|
|
859
|
-
|
|
812
|
+
const ctx = taskContext.ctx;
|
|
813
|
+
const response = await apiClient.batchTriggerV3({
|
|
814
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
860
815
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
861
816
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
817
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
862
818
|
return {
|
|
863
819
|
task: taskIdentifier,
|
|
864
820
|
payload: payloadPacket.data,
|
|
865
821
|
options: {
|
|
866
|
-
queue: item.options?.queue
|
|
822
|
+
queue: item.options?.queue
|
|
823
|
+
? { name: item.options.queue }
|
|
824
|
+
: queue
|
|
825
|
+
? { name: queue }
|
|
826
|
+
: undefined,
|
|
867
827
|
concurrencyKey: item.options?.concurrencyKey,
|
|
868
828
|
test: taskContext.ctx?.run.isTest,
|
|
869
829
|
payloadType: payloadPacket.dataType,
|
|
870
|
-
idempotencyKey: await makeIdempotencyKey(item.options?.idempotencyKey),
|
|
871
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
872
830
|
delay: item.options?.delay,
|
|
873
831
|
ttl: item.options?.ttl,
|
|
874
832
|
tags: item.options?.tags,
|
|
875
833
|
maxAttempts: item.options?.maxAttempts,
|
|
876
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
877
834
|
metadata: item.options?.metadata,
|
|
878
835
|
maxDuration: item.options?.maxDuration,
|
|
836
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
837
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
879
838
|
machine: item.options?.machine,
|
|
839
|
+
priority: item.options?.priority,
|
|
840
|
+
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
880
841
|
},
|
|
881
842
|
};
|
|
882
843
|
})),
|
|
844
|
+
parentRunId: ctx?.run.id,
|
|
883
845
|
}, {
|
|
884
846
|
spanParentAsLink: true,
|
|
885
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
886
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
887
847
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
888
848
|
}, {
|
|
889
849
|
name,
|
|
@@ -894,17 +854,8 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
894
854
|
if ("id" in body && typeof body.id === "string") {
|
|
895
855
|
span.setAttribute("batchId", body.id);
|
|
896
856
|
}
|
|
897
|
-
if ("
|
|
898
|
-
span.setAttribute("runCount", body.
|
|
899
|
-
}
|
|
900
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
901
|
-
if (body.isCached) {
|
|
902
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
903
|
-
}
|
|
904
|
-
span.setAttribute("isCached", body.isCached);
|
|
905
|
-
}
|
|
906
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
907
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
857
|
+
if ("runCount" in body && Array.isArray(body.runCount)) {
|
|
858
|
+
span.setAttribute("runCount", body.runCount);
|
|
908
859
|
}
|
|
909
860
|
}
|
|
910
861
|
},
|
|
@@ -912,9 +863,7 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
912
863
|
});
|
|
913
864
|
const handle = {
|
|
914
865
|
batchId: response.id,
|
|
915
|
-
|
|
916
|
-
idempotencyKey: response.idempotencyKey,
|
|
917
|
-
runs: response.runs,
|
|
866
|
+
runCount: response.runCount,
|
|
918
867
|
publicAccessToken: response.publicAccessToken,
|
|
919
868
|
};
|
|
920
869
|
return handle;
|
|
@@ -933,7 +882,7 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
933
882
|
options: {
|
|
934
883
|
dependentAttempt: ctx.attempt.id,
|
|
935
884
|
lockToVersion: taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
|
|
936
|
-
queue: options?.queue,
|
|
885
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
937
886
|
concurrencyKey: options?.concurrencyKey,
|
|
938
887
|
test: taskContext.ctx?.run.isTest,
|
|
939
888
|
payloadType: payloadPacket.dataType,
|
|
@@ -943,7 +892,13 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
943
892
|
maxAttempts: options?.maxAttempts,
|
|
944
893
|
metadata: options?.metadata,
|
|
945
894
|
maxDuration: options?.maxDuration,
|
|
895
|
+
resumeParentOnCompletion: true,
|
|
896
|
+
parentRunId: ctx.run.id,
|
|
897
|
+
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
898
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
946
899
|
machine: options?.machine,
|
|
900
|
+
priority: options?.priority,
|
|
901
|
+
releaseConcurrency: options?.releaseConcurrency,
|
|
947
902
|
},
|
|
948
903
|
}, {}, requestOptions);
|
|
949
904
|
span.setAttribute("runId", response.id);
|
|
@@ -975,16 +930,21 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
975
930
|
}
|
|
976
931
|
const apiClient = apiClientManager.clientOrThrow();
|
|
977
932
|
return await tracer.startActiveSpan(name, async (span) => {
|
|
978
|
-
const response = await apiClient.
|
|
979
|
-
items: await Promise.all(items.map(async (item) => {
|
|
933
|
+
const response = await apiClient.batchTriggerV3({
|
|
934
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
980
935
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
981
936
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
937
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
982
938
|
return {
|
|
983
939
|
task: id,
|
|
984
940
|
payload: payloadPacket.data,
|
|
985
941
|
options: {
|
|
986
942
|
lockToVersion: taskContext.worker?.version,
|
|
987
|
-
queue: item.options?.queue
|
|
943
|
+
queue: item.options?.queue
|
|
944
|
+
? { name: item.options.queue }
|
|
945
|
+
: queue
|
|
946
|
+
? { name: queue }
|
|
947
|
+
: undefined,
|
|
988
948
|
concurrencyKey: item.options?.concurrencyKey,
|
|
989
949
|
test: taskContext.ctx?.run.isTest,
|
|
990
950
|
payloadType: payloadPacket.dataType,
|
|
@@ -994,26 +954,24 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
994
954
|
maxAttempts: item.options?.maxAttempts,
|
|
995
955
|
metadata: item.options?.metadata,
|
|
996
956
|
maxDuration: item.options?.maxDuration,
|
|
957
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
958
|
+
batchItemIdempotencyKey,
|
|
959
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
997
960
|
machine: item.options?.machine,
|
|
961
|
+
priority: item.options?.priority,
|
|
998
962
|
},
|
|
999
963
|
};
|
|
1000
964
|
})),
|
|
1001
|
-
|
|
965
|
+
resumeParentOnCompletion: true,
|
|
966
|
+
parentRunId: ctx.run.id,
|
|
1002
967
|
}, {
|
|
1003
968
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
1004
969
|
}, requestOptions);
|
|
1005
970
|
span.setAttribute("batchId", response.id);
|
|
1006
|
-
span.setAttribute("runCount", response.
|
|
1007
|
-
span.setAttribute("isCached", response.isCached);
|
|
1008
|
-
if (response.isCached) {
|
|
1009
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
1010
|
-
}
|
|
1011
|
-
if (response.idempotencyKey) {
|
|
1012
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
1013
|
-
}
|
|
971
|
+
span.setAttribute("runCount", response.runCount);
|
|
1014
972
|
const result = await runtime.waitForBatch({
|
|
1015
973
|
id: response.id,
|
|
1016
|
-
|
|
974
|
+
runCount: response.runCount,
|
|
1017
975
|
ctx,
|
|
1018
976
|
});
|
|
1019
977
|
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
@@ -1093,4 +1051,62 @@ async function handleTaskRunExecutionResult(execution, taskIdentifier) {
|
|
|
1093
1051
|
};
|
|
1094
1052
|
}
|
|
1095
1053
|
}
|
|
1054
|
+
function registerTaskLifecycleHooks(taskId, params) {
|
|
1055
|
+
if (params.init) {
|
|
1056
|
+
lifecycleHooks.registerTaskInitHook(taskId, {
|
|
1057
|
+
fn: params.init,
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
if (params.onStart) {
|
|
1061
|
+
lifecycleHooks.registerTaskStartHook(taskId, {
|
|
1062
|
+
fn: params.onStart,
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
if (params.onFailure) {
|
|
1066
|
+
lifecycleHooks.registerTaskFailureHook(taskId, {
|
|
1067
|
+
fn: params.onFailure,
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
if (params.onSuccess) {
|
|
1071
|
+
lifecycleHooks.registerTaskSuccessHook(taskId, {
|
|
1072
|
+
fn: params.onSuccess,
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
if (params.onComplete) {
|
|
1076
|
+
lifecycleHooks.registerTaskCompleteHook(taskId, {
|
|
1077
|
+
fn: params.onComplete,
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
if (params.onWait) {
|
|
1081
|
+
lifecycleHooks.registerTaskWaitHook(taskId, {
|
|
1082
|
+
fn: params.onWait,
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
if (params.onResume) {
|
|
1086
|
+
lifecycleHooks.registerTaskResumeHook(taskId, {
|
|
1087
|
+
fn: params.onResume,
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
if (params.catchError) {
|
|
1091
|
+
// We don't need to use an adapter here because catchError is the new version of handleError
|
|
1092
|
+
lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1093
|
+
fn: params.catchError,
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
if (params.handleError) {
|
|
1097
|
+
lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1098
|
+
fn: params.handleError,
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
if (params.middleware) {
|
|
1102
|
+
lifecycleHooks.registerTaskMiddlewareHook(taskId, {
|
|
1103
|
+
fn: params.middleware,
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
if (params.cleanup) {
|
|
1107
|
+
lifecycleHooks.registerTaskCleanupHook(taskId, {
|
|
1108
|
+
fn: params.cleanup,
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1096
1112
|
//# sourceMappingURL=shared.js.map
|