@trigger.dev/sdk 3.3.17 → 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 +188 -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 +189 -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,39 +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,
|
|
349
324
|
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
350
325
|
},
|
|
351
326
|
};
|
|
352
327
|
})),
|
|
328
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
353
329
|
}, {
|
|
354
330
|
spanParentAsLink: true,
|
|
355
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
356
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
357
331
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
358
332
|
}, {
|
|
359
333
|
name: "batch.trigger()",
|
|
@@ -364,17 +338,8 @@ export async function batchTriggerById(items, options, requestOptions) {
|
|
|
364
338
|
if ("id" in body && typeof body.id === "string") {
|
|
365
339
|
span.setAttribute("batchId", body.id);
|
|
366
340
|
}
|
|
367
|
-
if ("
|
|
368
|
-
span.setAttribute("runCount", body.
|
|
369
|
-
}
|
|
370
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
371
|
-
if (body.isCached) {
|
|
372
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
373
|
-
}
|
|
374
|
-
span.setAttribute("isCached", body.isCached);
|
|
375
|
-
}
|
|
376
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
377
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
341
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
342
|
+
span.setAttribute("runCount", body.runCount);
|
|
378
343
|
}
|
|
379
344
|
}
|
|
380
345
|
},
|
|
@@ -382,9 +347,7 @@ export async function batchTriggerById(items, options, requestOptions) {
|
|
|
382
347
|
});
|
|
383
348
|
const handle = {
|
|
384
349
|
batchId: response.id,
|
|
385
|
-
|
|
386
|
-
idempotencyKey: response.idempotencyKey,
|
|
387
|
-
runs: response.runs,
|
|
350
|
+
runCount: response.runCount,
|
|
388
351
|
publicAccessToken: response.publicAccessToken,
|
|
389
352
|
};
|
|
390
353
|
return handle;
|
|
@@ -473,19 +436,20 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
473
436
|
}
|
|
474
437
|
const apiClient = apiClientManager.clientOrThrow();
|
|
475
438
|
return await tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
476
|
-
const response = await apiClient.
|
|
477
|
-
items: await Promise.all(items.map(async (item) => {
|
|
478
|
-
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);
|
|
479
442
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
480
443
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
481
444
|
: item.payload;
|
|
482
445
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
446
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
483
447
|
return {
|
|
484
448
|
task: item.id,
|
|
485
449
|
payload: payloadPacket.data,
|
|
486
450
|
options: {
|
|
487
451
|
lockToVersion: taskContext.worker?.version,
|
|
488
|
-
queue: item.options?.queue,
|
|
452
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
489
453
|
concurrencyKey: item.options?.concurrencyKey,
|
|
490
454
|
test: taskContext.ctx?.run.isTest,
|
|
491
455
|
payloadType: payloadPacket.dataType,
|
|
@@ -495,26 +459,24 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
495
459
|
maxAttempts: item.options?.maxAttempts,
|
|
496
460
|
metadata: item.options?.metadata,
|
|
497
461
|
maxDuration: item.options?.maxDuration,
|
|
462
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
463
|
+
batchItemIdempotencyKey,
|
|
464
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
498
465
|
machine: item.options?.machine,
|
|
466
|
+
priority: item.options?.priority,
|
|
499
467
|
},
|
|
500
468
|
};
|
|
501
469
|
})),
|
|
502
|
-
|
|
470
|
+
parentRunId: ctx.run.id,
|
|
471
|
+
resumeParentOnCompletion: true,
|
|
503
472
|
}, {
|
|
504
473
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
505
474
|
}, requestOptions);
|
|
506
475
|
span.setAttribute("batchId", response.id);
|
|
507
|
-
span.setAttribute("runCount", response.
|
|
508
|
-
span.setAttribute("isCached", response.isCached);
|
|
509
|
-
if (response.isCached) {
|
|
510
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
511
|
-
}
|
|
512
|
-
if (response.idempotencyKey) {
|
|
513
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
514
|
-
}
|
|
476
|
+
span.setAttribute("runCount", response.runCount);
|
|
515
477
|
const result = await runtime.waitForBatch({
|
|
516
478
|
id: response.id,
|
|
517
|
-
|
|
479
|
+
runCount: response.runCount,
|
|
518
480
|
ctx,
|
|
519
481
|
});
|
|
520
482
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -608,39 +570,39 @@ export async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
608
570
|
*/
|
|
609
571
|
export async function batchTriggerTasks(items, options, requestOptions) {
|
|
610
572
|
const apiClient = apiClientManager.clientOrThrow();
|
|
611
|
-
const response = await apiClient.
|
|
612
|
-
items: await Promise.all(items.map(async (item) => {
|
|
613
|
-
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);
|
|
614
576
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
615
577
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
616
578
|
: item.payload;
|
|
617
579
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
580
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
618
581
|
return {
|
|
619
582
|
task: item.task.id,
|
|
620
583
|
payload: payloadPacket.data,
|
|
621
584
|
options: {
|
|
622
|
-
queue: item.options?.queue,
|
|
585
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
623
586
|
concurrencyKey: item.options?.concurrencyKey,
|
|
624
587
|
test: taskContext.ctx?.run.isTest,
|
|
625
588
|
payloadType: payloadPacket.dataType,
|
|
626
|
-
idempotencyKey: await makeIdempotencyKey(item.options?.idempotencyKey),
|
|
627
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
628
589
|
delay: item.options?.delay,
|
|
629
590
|
ttl: item.options?.ttl,
|
|
630
591
|
tags: item.options?.tags,
|
|
631
592
|
maxAttempts: item.options?.maxAttempts,
|
|
632
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
633
593
|
metadata: item.options?.metadata,
|
|
634
594
|
maxDuration: item.options?.maxDuration,
|
|
595
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
596
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
635
597
|
machine: item.options?.machine,
|
|
598
|
+
priority: item.options?.priority,
|
|
636
599
|
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
637
600
|
},
|
|
638
601
|
};
|
|
639
602
|
})),
|
|
603
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
640
604
|
}, {
|
|
641
605
|
spanParentAsLink: true,
|
|
642
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
643
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
644
606
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
645
607
|
}, {
|
|
646
608
|
name: "batch.triggerByTask()",
|
|
@@ -651,17 +613,8 @@ export async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
651
613
|
if ("id" in body && typeof body.id === "string") {
|
|
652
614
|
span.setAttribute("batchId", body.id);
|
|
653
615
|
}
|
|
654
|
-
if ("
|
|
655
|
-
span.setAttribute("runCount", body.
|
|
656
|
-
}
|
|
657
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
658
|
-
if (body.isCached) {
|
|
659
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
660
|
-
}
|
|
661
|
-
span.setAttribute("isCached", body.isCached);
|
|
662
|
-
}
|
|
663
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
664
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
616
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
617
|
+
span.setAttribute("runCount", body.runCount);
|
|
665
618
|
}
|
|
666
619
|
}
|
|
667
620
|
},
|
|
@@ -669,9 +622,7 @@ export async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
669
622
|
});
|
|
670
623
|
const handle = {
|
|
671
624
|
batchId: response.id,
|
|
672
|
-
|
|
673
|
-
idempotencyKey: response.idempotencyKey,
|
|
674
|
-
runs: response.runs,
|
|
625
|
+
runCount: response.runCount,
|
|
675
626
|
publicAccessToken: response.publicAccessToken,
|
|
676
627
|
};
|
|
677
628
|
return handle;
|
|
@@ -760,19 +711,20 @@ export async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
760
711
|
}
|
|
761
712
|
const apiClient = apiClientManager.clientOrThrow();
|
|
762
713
|
return await tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
763
|
-
const response = await apiClient.
|
|
764
|
-
items: await Promise.all(items.map(async (item) => {
|
|
765
|
-
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);
|
|
766
717
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
767
718
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
768
719
|
: item.payload;
|
|
769
720
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
721
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
770
722
|
return {
|
|
771
723
|
task: item.task.id,
|
|
772
724
|
payload: payloadPacket.data,
|
|
773
725
|
options: {
|
|
774
726
|
lockToVersion: taskContext.worker?.version,
|
|
775
|
-
queue: item.options?.queue,
|
|
727
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
776
728
|
concurrencyKey: item.options?.concurrencyKey,
|
|
777
729
|
test: taskContext.ctx?.run.isTest,
|
|
778
730
|
payloadType: payloadPacket.dataType,
|
|
@@ -782,26 +734,24 @@ export async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
782
734
|
maxAttempts: item.options?.maxAttempts,
|
|
783
735
|
metadata: item.options?.metadata,
|
|
784
736
|
maxDuration: item.options?.maxDuration,
|
|
737
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
738
|
+
batchItemIdempotencyKey,
|
|
739
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
785
740
|
machine: item.options?.machine,
|
|
741
|
+
priority: item.options?.priority,
|
|
786
742
|
},
|
|
787
743
|
};
|
|
788
744
|
})),
|
|
789
|
-
|
|
745
|
+
parentRunId: ctx.run.id,
|
|
746
|
+
resumeParentOnCompletion: true,
|
|
790
747
|
}, {
|
|
791
748
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
792
749
|
}, requestOptions);
|
|
793
750
|
span.setAttribute("batchId", response.id);
|
|
794
|
-
span.setAttribute("runCount", response.
|
|
795
|
-
span.setAttribute("isCached", response.isCached);
|
|
796
|
-
if (response.isCached) {
|
|
797
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
798
|
-
}
|
|
799
|
-
if (response.idempotencyKey) {
|
|
800
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
801
|
-
}
|
|
751
|
+
span.setAttribute("runCount", response.runCount);
|
|
802
752
|
const result = await runtime.waitForBatch({
|
|
803
753
|
id: response.id,
|
|
804
|
-
|
|
754
|
+
runCount: response.runCount,
|
|
805
755
|
ctx,
|
|
806
756
|
});
|
|
807
757
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -823,7 +773,7 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
823
773
|
const handle = await apiClient.triggerTask(id, {
|
|
824
774
|
payload: payloadPacket.data,
|
|
825
775
|
options: {
|
|
826
|
-
queue: options?.queue,
|
|
776
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
827
777
|
concurrencyKey: options?.concurrencyKey,
|
|
828
778
|
test: taskContext.ctx?.run.isTest,
|
|
829
779
|
payloadType: payloadPacket.dataType,
|
|
@@ -833,10 +783,11 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
833
783
|
ttl: options?.ttl,
|
|
834
784
|
tags: options?.tags,
|
|
835
785
|
maxAttempts: options?.maxAttempts,
|
|
836
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
837
786
|
metadata: options?.metadata,
|
|
838
787
|
maxDuration: options?.maxDuration,
|
|
788
|
+
parentRunId: taskContext.ctx?.run.id,
|
|
839
789
|
machine: options?.machine,
|
|
790
|
+
priority: options?.priority,
|
|
840
791
|
lockToVersion: options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
841
792
|
},
|
|
842
793
|
}, {
|
|
@@ -858,36 +809,41 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
858
809
|
}
|
|
859
810
|
async function batchTrigger_internal(name, taskIdentifier, items, options, parsePayload, requestOptions, queue) {
|
|
860
811
|
const apiClient = apiClientManager.clientOrThrow();
|
|
861
|
-
const
|
|
862
|
-
|
|
812
|
+
const ctx = taskContext.ctx;
|
|
813
|
+
const response = await apiClient.batchTriggerV3({
|
|
814
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
863
815
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
864
816
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
817
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
865
818
|
return {
|
|
866
819
|
task: taskIdentifier,
|
|
867
820
|
payload: payloadPacket.data,
|
|
868
821
|
options: {
|
|
869
|
-
queue: item.options?.queue
|
|
822
|
+
queue: item.options?.queue
|
|
823
|
+
? { name: item.options.queue }
|
|
824
|
+
: queue
|
|
825
|
+
? { name: queue }
|
|
826
|
+
: undefined,
|
|
870
827
|
concurrencyKey: item.options?.concurrencyKey,
|
|
871
828
|
test: taskContext.ctx?.run.isTest,
|
|
872
829
|
payloadType: payloadPacket.dataType,
|
|
873
|
-
idempotencyKey: await makeIdempotencyKey(item.options?.idempotencyKey),
|
|
874
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
875
830
|
delay: item.options?.delay,
|
|
876
831
|
ttl: item.options?.ttl,
|
|
877
832
|
tags: item.options?.tags,
|
|
878
833
|
maxAttempts: item.options?.maxAttempts,
|
|
879
|
-
parentAttempt: taskContext.ctx?.attempt.id,
|
|
880
834
|
metadata: item.options?.metadata,
|
|
881
835
|
maxDuration: item.options?.maxDuration,
|
|
836
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
837
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
882
838
|
machine: item.options?.machine,
|
|
839
|
+
priority: item.options?.priority,
|
|
883
840
|
lockToVersion: item.options?.version ?? getEnvVar("TRIGGER_VERSION"),
|
|
884
841
|
},
|
|
885
842
|
};
|
|
886
843
|
})),
|
|
844
|
+
parentRunId: ctx?.run.id,
|
|
887
845
|
}, {
|
|
888
846
|
spanParentAsLink: true,
|
|
889
|
-
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
890
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
891
847
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
892
848
|
}, {
|
|
893
849
|
name,
|
|
@@ -898,17 +854,8 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
898
854
|
if ("id" in body && typeof body.id === "string") {
|
|
899
855
|
span.setAttribute("batchId", body.id);
|
|
900
856
|
}
|
|
901
|
-
if ("
|
|
902
|
-
span.setAttribute("runCount", body.
|
|
903
|
-
}
|
|
904
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
905
|
-
if (body.isCached) {
|
|
906
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
907
|
-
}
|
|
908
|
-
span.setAttribute("isCached", body.isCached);
|
|
909
|
-
}
|
|
910
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
911
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
857
|
+
if ("runCount" in body && Array.isArray(body.runCount)) {
|
|
858
|
+
span.setAttribute("runCount", body.runCount);
|
|
912
859
|
}
|
|
913
860
|
}
|
|
914
861
|
},
|
|
@@ -916,9 +863,7 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
916
863
|
});
|
|
917
864
|
const handle = {
|
|
918
865
|
batchId: response.id,
|
|
919
|
-
|
|
920
|
-
idempotencyKey: response.idempotencyKey,
|
|
921
|
-
runs: response.runs,
|
|
866
|
+
runCount: response.runCount,
|
|
922
867
|
publicAccessToken: response.publicAccessToken,
|
|
923
868
|
};
|
|
924
869
|
return handle;
|
|
@@ -937,7 +882,7 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
937
882
|
options: {
|
|
938
883
|
dependentAttempt: ctx.attempt.id,
|
|
939
884
|
lockToVersion: taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
|
|
940
|
-
queue: options?.queue,
|
|
885
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
941
886
|
concurrencyKey: options?.concurrencyKey,
|
|
942
887
|
test: taskContext.ctx?.run.isTest,
|
|
943
888
|
payloadType: payloadPacket.dataType,
|
|
@@ -947,7 +892,13 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
947
892
|
maxAttempts: options?.maxAttempts,
|
|
948
893
|
metadata: options?.metadata,
|
|
949
894
|
maxDuration: options?.maxDuration,
|
|
895
|
+
resumeParentOnCompletion: true,
|
|
896
|
+
parentRunId: ctx.run.id,
|
|
897
|
+
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
898
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
950
899
|
machine: options?.machine,
|
|
900
|
+
priority: options?.priority,
|
|
901
|
+
releaseConcurrency: options?.releaseConcurrency,
|
|
951
902
|
},
|
|
952
903
|
}, {}, requestOptions);
|
|
953
904
|
span.setAttribute("runId", response.id);
|
|
@@ -979,16 +930,21 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
979
930
|
}
|
|
980
931
|
const apiClient = apiClientManager.clientOrThrow();
|
|
981
932
|
return await tracer.startActiveSpan(name, async (span) => {
|
|
982
|
-
const response = await apiClient.
|
|
983
|
-
items: await Promise.all(items.map(async (item) => {
|
|
933
|
+
const response = await apiClient.batchTriggerV3({
|
|
934
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
984
935
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
985
936
|
const payloadPacket = await stringifyIO(parsedPayload);
|
|
937
|
+
const batchItemIdempotencyKey = await makeIdempotencyKey(flattenIdempotencyKey([options?.idempotencyKey, `${index}`]));
|
|
986
938
|
return {
|
|
987
939
|
task: id,
|
|
988
940
|
payload: payloadPacket.data,
|
|
989
941
|
options: {
|
|
990
942
|
lockToVersion: taskContext.worker?.version,
|
|
991
|
-
queue: item.options?.queue
|
|
943
|
+
queue: item.options?.queue
|
|
944
|
+
? { name: item.options.queue }
|
|
945
|
+
: queue
|
|
946
|
+
? { name: queue }
|
|
947
|
+
: undefined,
|
|
992
948
|
concurrencyKey: item.options?.concurrencyKey,
|
|
993
949
|
test: taskContext.ctx?.run.isTest,
|
|
994
950
|
payloadType: payloadPacket.dataType,
|
|
@@ -998,26 +954,24 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
998
954
|
maxAttempts: item.options?.maxAttempts,
|
|
999
955
|
metadata: item.options?.metadata,
|
|
1000
956
|
maxDuration: item.options?.maxDuration,
|
|
957
|
+
idempotencyKey: (await makeIdempotencyKey(item.options?.idempotencyKey)) ??
|
|
958
|
+
batchItemIdempotencyKey,
|
|
959
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1001
960
|
machine: item.options?.machine,
|
|
961
|
+
priority: item.options?.priority,
|
|
1002
962
|
},
|
|
1003
963
|
};
|
|
1004
964
|
})),
|
|
1005
|
-
|
|
965
|
+
resumeParentOnCompletion: true,
|
|
966
|
+
parentRunId: ctx.run.id,
|
|
1006
967
|
}, {
|
|
1007
968
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
1008
969
|
}, requestOptions);
|
|
1009
970
|
span.setAttribute("batchId", response.id);
|
|
1010
|
-
span.setAttribute("runCount", response.
|
|
1011
|
-
span.setAttribute("isCached", response.isCached);
|
|
1012
|
-
if (response.isCached) {
|
|
1013
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
1014
|
-
}
|
|
1015
|
-
if (response.idempotencyKey) {
|
|
1016
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
1017
|
-
}
|
|
971
|
+
span.setAttribute("runCount", response.runCount);
|
|
1018
972
|
const result = await runtime.waitForBatch({
|
|
1019
973
|
id: response.id,
|
|
1020
|
-
|
|
974
|
+
runCount: response.runCount,
|
|
1021
975
|
ctx,
|
|
1022
976
|
});
|
|
1023
977
|
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
@@ -1097,4 +1051,62 @@ async function handleTaskRunExecutionResult(execution, taskIdentifier) {
|
|
|
1097
1051
|
};
|
|
1098
1052
|
}
|
|
1099
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
|
+
}
|
|
1100
1112
|
//# sourceMappingURL=shared.js.map
|