@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
|
@@ -21,40 +21,28 @@ Object.defineProperty(exports, "TaskRunPromise", { enumerable: true, get: functi
|
|
|
21
21
|
const runs_js_1 = require("./runs.js");
|
|
22
22
|
const tracer_js_1 = require("./tracer.js");
|
|
23
23
|
function queue(options) {
|
|
24
|
+
v3_1.resourceCatalog.registerQueueMetadata(options);
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
options[Symbol.for("trigger.dev/queue")] = true;
|
|
24
27
|
return options;
|
|
25
28
|
}
|
|
26
29
|
function createTask(params) {
|
|
27
|
-
const customQueue = params.queue
|
|
28
|
-
? queue({
|
|
29
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
30
|
-
...params.queue,
|
|
31
|
-
})
|
|
32
|
-
: undefined;
|
|
33
30
|
const task = {
|
|
34
31
|
id: params.id,
|
|
35
32
|
description: params.description,
|
|
36
33
|
trigger: async (payload, options) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
40
|
-
: `trigger()`, params.id, payload, undefined, {
|
|
41
|
-
queue: customQueue,
|
|
34
|
+
return await trigger_internal("trigger()", params.id, payload, undefined, {
|
|
35
|
+
queue: params.queue?.name,
|
|
42
36
|
...options,
|
|
43
37
|
});
|
|
44
38
|
},
|
|
45
39
|
batchTrigger: async (items, options) => {
|
|
46
|
-
|
|
47
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
48
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
49
|
-
: `batchTrigger()`, params.id, items, options, undefined, undefined, customQueue);
|
|
40
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, undefined, undefined, params.queue?.name);
|
|
50
41
|
},
|
|
51
42
|
triggerAndWait: (payload, options) => {
|
|
52
|
-
const taskMetadata = v3_1.taskCatalog.getTaskManifest(params.id);
|
|
53
43
|
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
54
|
-
triggerAndWait_internal(
|
|
55
|
-
|
|
56
|
-
: `triggerAndWait()`, params.id, payload, undefined, {
|
|
57
|
-
queue: customQueue,
|
|
44
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, undefined, {
|
|
45
|
+
queue: params.queue?.name,
|
|
58
46
|
...options,
|
|
59
47
|
})
|
|
60
48
|
.then((result) => {
|
|
@@ -66,13 +54,11 @@ function createTask(params) {
|
|
|
66
54
|
}, params.id);
|
|
67
55
|
},
|
|
68
56
|
batchTriggerAndWait: async (items, options) => {
|
|
69
|
-
|
|
70
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
71
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
72
|
-
: `batchTriggerAndWait()`, params.id, items, undefined, options, undefined, customQueue);
|
|
57
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, undefined, options, undefined, params.queue?.name);
|
|
73
58
|
},
|
|
74
59
|
};
|
|
75
|
-
|
|
60
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
61
|
+
v3_1.resourceCatalog.registerTaskMetadata({
|
|
76
62
|
id: params.id,
|
|
77
63
|
description: params.description,
|
|
78
64
|
queue: params.queue,
|
|
@@ -81,19 +67,23 @@ function createTask(params) {
|
|
|
81
67
|
maxDuration: params.maxDuration,
|
|
82
68
|
fns: {
|
|
83
69
|
run: params.run,
|
|
84
|
-
init: params.init,
|
|
85
|
-
cleanup: params.cleanup,
|
|
86
|
-
middleware: params.middleware,
|
|
87
|
-
handleError: params.handleError,
|
|
88
|
-
onSuccess: params.onSuccess,
|
|
89
|
-
onFailure: params.onFailure,
|
|
90
|
-
onStart: params.onStart,
|
|
91
70
|
},
|
|
92
71
|
});
|
|
72
|
+
const queue = params.queue;
|
|
73
|
+
if (queue && typeof queue.name === "string") {
|
|
74
|
+
v3_1.resourceCatalog.registerQueueMetadata({
|
|
75
|
+
name: queue.name,
|
|
76
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
77
|
+
releaseConcurrencyOnWaitpoint: queue.releaseConcurrencyOnWaitpoint,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
93
80
|
// @ts-expect-error
|
|
94
81
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
95
82
|
return task;
|
|
96
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated use ai.tool() instead
|
|
86
|
+
*/
|
|
97
87
|
function createToolTask(params) {
|
|
98
88
|
const task = createSchemaTask({
|
|
99
89
|
...params,
|
|
@@ -111,12 +101,6 @@ function createToolTask(params) {
|
|
|
111
101
|
};
|
|
112
102
|
}
|
|
113
103
|
function createSchemaTask(params) {
|
|
114
|
-
const customQueue = params.queue
|
|
115
|
-
? queue({
|
|
116
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
117
|
-
...params.queue,
|
|
118
|
-
})
|
|
119
|
-
: undefined;
|
|
120
104
|
const parsePayload = params.schema
|
|
121
105
|
? (0, v3_1.getSchemaParseFn)(params.schema)
|
|
122
106
|
: undefined;
|
|
@@ -125,27 +109,18 @@ function createSchemaTask(params) {
|
|
|
125
109
|
description: params.description,
|
|
126
110
|
schema: params.schema,
|
|
127
111
|
trigger: async (payload, options, requestOptions) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
131
|
-
: `trigger()`, params.id, payload, parsePayload, {
|
|
132
|
-
queue: customQueue,
|
|
112
|
+
return await trigger_internal("trigger()", params.id, payload, parsePayload, {
|
|
113
|
+
queue: params.queue?.name,
|
|
133
114
|
...options,
|
|
134
115
|
}, requestOptions);
|
|
135
116
|
},
|
|
136
117
|
batchTrigger: async (items, options, requestOptions) => {
|
|
137
|
-
|
|
138
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
139
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
140
|
-
: `batchTrigger()`, params.id, items, options, parsePayload, requestOptions, customQueue);
|
|
118
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, parsePayload, requestOptions, params.queue?.name);
|
|
141
119
|
},
|
|
142
120
|
triggerAndWait: (payload, options) => {
|
|
143
|
-
const taskMetadata = v3_1.taskCatalog.getTaskManifest(params.id);
|
|
144
121
|
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
145
|
-
triggerAndWait_internal(
|
|
146
|
-
|
|
147
|
-
: `triggerAndWait()`, params.id, payload, parsePayload, {
|
|
148
|
-
queue: customQueue,
|
|
122
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, parsePayload, {
|
|
123
|
+
queue: params.queue?.name,
|
|
149
124
|
...options,
|
|
150
125
|
})
|
|
151
126
|
.then((result) => {
|
|
@@ -157,13 +132,11 @@ function createSchemaTask(params) {
|
|
|
157
132
|
}, params.id);
|
|
158
133
|
},
|
|
159
134
|
batchTriggerAndWait: async (items, options) => {
|
|
160
|
-
|
|
161
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
162
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
163
|
-
: `batchTriggerAndWait()`, params.id, items, parsePayload, options, undefined, customQueue);
|
|
135
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, parsePayload, options, undefined, params.queue?.name);
|
|
164
136
|
},
|
|
165
137
|
};
|
|
166
|
-
|
|
138
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
139
|
+
v3_1.resourceCatalog.registerTaskMetadata({
|
|
167
140
|
id: params.id,
|
|
168
141
|
description: params.description,
|
|
169
142
|
queue: params.queue,
|
|
@@ -172,16 +145,17 @@ function createSchemaTask(params) {
|
|
|
172
145
|
maxDuration: params.maxDuration,
|
|
173
146
|
fns: {
|
|
174
147
|
run: params.run,
|
|
175
|
-
init: params.init,
|
|
176
|
-
cleanup: params.cleanup,
|
|
177
|
-
middleware: params.middleware,
|
|
178
|
-
handleError: params.handleError,
|
|
179
|
-
onSuccess: params.onSuccess,
|
|
180
|
-
onFailure: params.onFailure,
|
|
181
|
-
onStart: params.onStart,
|
|
182
148
|
parsePayload,
|
|
183
149
|
},
|
|
184
150
|
});
|
|
151
|
+
const queue = params.queue;
|
|
152
|
+
if (queue && typeof queue.name === "string") {
|
|
153
|
+
v3_1.resourceCatalog.registerQueueMetadata({
|
|
154
|
+
name: queue.name,
|
|
155
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
156
|
+
releaseConcurrencyOnWaitpoint: queue.releaseConcurrencyOnWaitpoint,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
185
159
|
// @ts-expect-error
|
|
186
160
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
187
161
|
return task;
|
|
@@ -338,39 +312,39 @@ async function batchTrigger(id, items, options, requestOptions) {
|
|
|
338
312
|
*/
|
|
339
313
|
async function batchTriggerById(items, options, requestOptions) {
|
|
340
314
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
341
|
-
const response = await apiClient.
|
|
342
|
-
items: await Promise.all(items.map(async (item) => {
|
|
343
|
-
const taskMetadata = v3_1.
|
|
315
|
+
const response = await apiClient.batchTriggerV3({
|
|
316
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
317
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
344
318
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
345
319
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
346
320
|
: item.payload;
|
|
347
321
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
322
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
348
323
|
return {
|
|
349
324
|
task: item.id,
|
|
350
325
|
payload: payloadPacket.data,
|
|
351
326
|
options: {
|
|
352
|
-
queue: item.options?.queue,
|
|
327
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
353
328
|
concurrencyKey: item.options?.concurrencyKey,
|
|
354
329
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
355
330
|
payloadType: payloadPacket.dataType,
|
|
356
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
357
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
358
331
|
delay: item.options?.delay,
|
|
359
332
|
ttl: item.options?.ttl,
|
|
360
333
|
tags: item.options?.tags,
|
|
361
334
|
maxAttempts: item.options?.maxAttempts,
|
|
362
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
363
335
|
metadata: item.options?.metadata,
|
|
364
336
|
maxDuration: item.options?.maxDuration,
|
|
337
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
338
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
365
339
|
machine: item.options?.machine,
|
|
340
|
+
priority: item.options?.priority,
|
|
366
341
|
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
367
342
|
},
|
|
368
343
|
};
|
|
369
344
|
})),
|
|
345
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
370
346
|
}, {
|
|
371
347
|
spanParentAsLink: true,
|
|
372
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
373
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
374
348
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
375
349
|
}, {
|
|
376
350
|
name: "batch.trigger()",
|
|
@@ -381,17 +355,8 @@ async function batchTriggerById(items, options, requestOptions) {
|
|
|
381
355
|
if ("id" in body && typeof body.id === "string") {
|
|
382
356
|
span.setAttribute("batchId", body.id);
|
|
383
357
|
}
|
|
384
|
-
if ("
|
|
385
|
-
span.setAttribute("runCount", body.
|
|
386
|
-
}
|
|
387
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
388
|
-
if (body.isCached) {
|
|
389
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
390
|
-
}
|
|
391
|
-
span.setAttribute("isCached", body.isCached);
|
|
392
|
-
}
|
|
393
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
394
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
358
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
359
|
+
span.setAttribute("runCount", body.runCount);
|
|
395
360
|
}
|
|
396
361
|
}
|
|
397
362
|
},
|
|
@@ -399,9 +364,7 @@ async function batchTriggerById(items, options, requestOptions) {
|
|
|
399
364
|
});
|
|
400
365
|
const handle = {
|
|
401
366
|
batchId: response.id,
|
|
402
|
-
|
|
403
|
-
idempotencyKey: response.idempotencyKey,
|
|
404
|
-
runs: response.runs,
|
|
367
|
+
runCount: response.runCount,
|
|
405
368
|
publicAccessToken: response.publicAccessToken,
|
|
406
369
|
};
|
|
407
370
|
return handle;
|
|
@@ -490,19 +453,20 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
490
453
|
}
|
|
491
454
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
492
455
|
return await tracer_js_1.tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
493
|
-
const response = await apiClient.
|
|
494
|
-
items: await Promise.all(items.map(async (item) => {
|
|
495
|
-
const taskMetadata = v3_1.
|
|
456
|
+
const response = await apiClient.batchTriggerV3({
|
|
457
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
458
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
496
459
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
497
460
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
498
461
|
: item.payload;
|
|
499
462
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
463
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
500
464
|
return {
|
|
501
465
|
task: item.id,
|
|
502
466
|
payload: payloadPacket.data,
|
|
503
467
|
options: {
|
|
504
468
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
505
|
-
queue: item.options?.queue,
|
|
469
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
506
470
|
concurrencyKey: item.options?.concurrencyKey,
|
|
507
471
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
508
472
|
payloadType: payloadPacket.dataType,
|
|
@@ -512,26 +476,24 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
512
476
|
maxAttempts: item.options?.maxAttempts,
|
|
513
477
|
metadata: item.options?.metadata,
|
|
514
478
|
maxDuration: item.options?.maxDuration,
|
|
479
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
480
|
+
batchItemIdempotencyKey,
|
|
481
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
515
482
|
machine: item.options?.machine,
|
|
483
|
+
priority: item.options?.priority,
|
|
516
484
|
},
|
|
517
485
|
};
|
|
518
486
|
})),
|
|
519
|
-
|
|
487
|
+
parentRunId: ctx.run.id,
|
|
488
|
+
resumeParentOnCompletion: true,
|
|
520
489
|
}, {
|
|
521
490
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
522
491
|
}, requestOptions);
|
|
523
492
|
span.setAttribute("batchId", response.id);
|
|
524
|
-
span.setAttribute("runCount", response.
|
|
525
|
-
span.setAttribute("isCached", response.isCached);
|
|
526
|
-
if (response.isCached) {
|
|
527
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
528
|
-
}
|
|
529
|
-
if (response.idempotencyKey) {
|
|
530
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
531
|
-
}
|
|
493
|
+
span.setAttribute("runCount", response.runCount);
|
|
532
494
|
const result = await v3_1.runtime.waitForBatch({
|
|
533
495
|
id: response.id,
|
|
534
|
-
|
|
496
|
+
runCount: response.runCount,
|
|
535
497
|
ctx,
|
|
536
498
|
});
|
|
537
499
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -625,39 +587,39 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
625
587
|
*/
|
|
626
588
|
async function batchTriggerTasks(items, options, requestOptions) {
|
|
627
589
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
628
|
-
const response = await apiClient.
|
|
629
|
-
items: await Promise.all(items.map(async (item) => {
|
|
630
|
-
const taskMetadata = v3_1.
|
|
590
|
+
const response = await apiClient.batchTriggerV3({
|
|
591
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
592
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
631
593
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
632
594
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
633
595
|
: item.payload;
|
|
634
596
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
597
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
635
598
|
return {
|
|
636
599
|
task: item.task.id,
|
|
637
600
|
payload: payloadPacket.data,
|
|
638
601
|
options: {
|
|
639
|
-
queue: item.options?.queue,
|
|
602
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
640
603
|
concurrencyKey: item.options?.concurrencyKey,
|
|
641
604
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
642
605
|
payloadType: payloadPacket.dataType,
|
|
643
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
644
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
645
606
|
delay: item.options?.delay,
|
|
646
607
|
ttl: item.options?.ttl,
|
|
647
608
|
tags: item.options?.tags,
|
|
648
609
|
maxAttempts: item.options?.maxAttempts,
|
|
649
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
650
610
|
metadata: item.options?.metadata,
|
|
651
611
|
maxDuration: item.options?.maxDuration,
|
|
612
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
613
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
652
614
|
machine: item.options?.machine,
|
|
615
|
+
priority: item.options?.priority,
|
|
653
616
|
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
654
617
|
},
|
|
655
618
|
};
|
|
656
619
|
})),
|
|
620
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
657
621
|
}, {
|
|
658
622
|
spanParentAsLink: true,
|
|
659
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
660
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
661
623
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
662
624
|
}, {
|
|
663
625
|
name: "batch.triggerByTask()",
|
|
@@ -668,17 +630,8 @@ async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
668
630
|
if ("id" in body && typeof body.id === "string") {
|
|
669
631
|
span.setAttribute("batchId", body.id);
|
|
670
632
|
}
|
|
671
|
-
if ("
|
|
672
|
-
span.setAttribute("runCount", body.
|
|
673
|
-
}
|
|
674
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
675
|
-
if (body.isCached) {
|
|
676
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
677
|
-
}
|
|
678
|
-
span.setAttribute("isCached", body.isCached);
|
|
679
|
-
}
|
|
680
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
681
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
633
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
634
|
+
span.setAttribute("runCount", body.runCount);
|
|
682
635
|
}
|
|
683
636
|
}
|
|
684
637
|
},
|
|
@@ -686,9 +639,7 @@ async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
686
639
|
});
|
|
687
640
|
const handle = {
|
|
688
641
|
batchId: response.id,
|
|
689
|
-
|
|
690
|
-
idempotencyKey: response.idempotencyKey,
|
|
691
|
-
runs: response.runs,
|
|
642
|
+
runCount: response.runCount,
|
|
692
643
|
publicAccessToken: response.publicAccessToken,
|
|
693
644
|
};
|
|
694
645
|
return handle;
|
|
@@ -777,19 +728,20 @@ async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
777
728
|
}
|
|
778
729
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
779
730
|
return await tracer_js_1.tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
780
|
-
const response = await apiClient.
|
|
781
|
-
items: await Promise.all(items.map(async (item) => {
|
|
782
|
-
const taskMetadata = v3_1.
|
|
731
|
+
const response = await apiClient.batchTriggerV3({
|
|
732
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
733
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
783
734
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
784
735
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
785
736
|
: item.payload;
|
|
786
737
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
738
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
787
739
|
return {
|
|
788
740
|
task: item.task.id,
|
|
789
741
|
payload: payloadPacket.data,
|
|
790
742
|
options: {
|
|
791
743
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
792
|
-
queue: item.options?.queue,
|
|
744
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
793
745
|
concurrencyKey: item.options?.concurrencyKey,
|
|
794
746
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
795
747
|
payloadType: payloadPacket.dataType,
|
|
@@ -799,26 +751,24 @@ async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
799
751
|
maxAttempts: item.options?.maxAttempts,
|
|
800
752
|
metadata: item.options?.metadata,
|
|
801
753
|
maxDuration: item.options?.maxDuration,
|
|
754
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
755
|
+
batchItemIdempotencyKey,
|
|
756
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
802
757
|
machine: item.options?.machine,
|
|
758
|
+
priority: item.options?.priority,
|
|
803
759
|
},
|
|
804
760
|
};
|
|
805
761
|
})),
|
|
806
|
-
|
|
762
|
+
parentRunId: ctx.run.id,
|
|
763
|
+
resumeParentOnCompletion: true,
|
|
807
764
|
}, {
|
|
808
765
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
809
766
|
}, requestOptions);
|
|
810
767
|
span.setAttribute("batchId", response.id);
|
|
811
|
-
span.setAttribute("runCount", response.
|
|
812
|
-
span.setAttribute("isCached", response.isCached);
|
|
813
|
-
if (response.isCached) {
|
|
814
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
815
|
-
}
|
|
816
|
-
if (response.idempotencyKey) {
|
|
817
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
818
|
-
}
|
|
768
|
+
span.setAttribute("runCount", response.runCount);
|
|
819
769
|
const result = await v3_1.runtime.waitForBatch({
|
|
820
770
|
id: response.id,
|
|
821
|
-
|
|
771
|
+
runCount: response.runCount,
|
|
822
772
|
ctx,
|
|
823
773
|
});
|
|
824
774
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -840,7 +790,7 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
840
790
|
const handle = await apiClient.triggerTask(id, {
|
|
841
791
|
payload: payloadPacket.data,
|
|
842
792
|
options: {
|
|
843
|
-
queue: options?.queue,
|
|
793
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
844
794
|
concurrencyKey: options?.concurrencyKey,
|
|
845
795
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
846
796
|
payloadType: payloadPacket.dataType,
|
|
@@ -850,10 +800,11 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
850
800
|
ttl: options?.ttl,
|
|
851
801
|
tags: options?.tags,
|
|
852
802
|
maxAttempts: options?.maxAttempts,
|
|
853
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
854
803
|
metadata: options?.metadata,
|
|
855
804
|
maxDuration: options?.maxDuration,
|
|
805
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
856
806
|
machine: options?.machine,
|
|
807
|
+
priority: options?.priority,
|
|
857
808
|
lockToVersion: options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
858
809
|
},
|
|
859
810
|
}, {
|
|
@@ -875,36 +826,41 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
875
826
|
}
|
|
876
827
|
async function batchTrigger_internal(name, taskIdentifier, items, options, parsePayload, requestOptions, queue) {
|
|
877
828
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
878
|
-
const
|
|
879
|
-
|
|
829
|
+
const ctx = v3_1.taskContext.ctx;
|
|
830
|
+
const response = await apiClient.batchTriggerV3({
|
|
831
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
880
832
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
881
833
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
834
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
882
835
|
return {
|
|
883
836
|
task: taskIdentifier,
|
|
884
837
|
payload: payloadPacket.data,
|
|
885
838
|
options: {
|
|
886
|
-
queue: item.options?.queue
|
|
839
|
+
queue: item.options?.queue
|
|
840
|
+
? { name: item.options.queue }
|
|
841
|
+
: queue
|
|
842
|
+
? { name: queue }
|
|
843
|
+
: undefined,
|
|
887
844
|
concurrencyKey: item.options?.concurrencyKey,
|
|
888
845
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
889
846
|
payloadType: payloadPacket.dataType,
|
|
890
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
891
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
892
847
|
delay: item.options?.delay,
|
|
893
848
|
ttl: item.options?.ttl,
|
|
894
849
|
tags: item.options?.tags,
|
|
895
850
|
maxAttempts: item.options?.maxAttempts,
|
|
896
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
897
851
|
metadata: item.options?.metadata,
|
|
898
852
|
maxDuration: item.options?.maxDuration,
|
|
853
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
854
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
899
855
|
machine: item.options?.machine,
|
|
856
|
+
priority: item.options?.priority,
|
|
900
857
|
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
901
858
|
},
|
|
902
859
|
};
|
|
903
860
|
})),
|
|
861
|
+
parentRunId: ctx?.run.id,
|
|
904
862
|
}, {
|
|
905
863
|
spanParentAsLink: true,
|
|
906
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
907
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
908
864
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
909
865
|
}, {
|
|
910
866
|
name,
|
|
@@ -915,17 +871,8 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
915
871
|
if ("id" in body && typeof body.id === "string") {
|
|
916
872
|
span.setAttribute("batchId", body.id);
|
|
917
873
|
}
|
|
918
|
-
if ("
|
|
919
|
-
span.setAttribute("runCount", body.
|
|
920
|
-
}
|
|
921
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
922
|
-
if (body.isCached) {
|
|
923
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
924
|
-
}
|
|
925
|
-
span.setAttribute("isCached", body.isCached);
|
|
926
|
-
}
|
|
927
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
928
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
874
|
+
if ("runCount" in body && Array.isArray(body.runCount)) {
|
|
875
|
+
span.setAttribute("runCount", body.runCount);
|
|
929
876
|
}
|
|
930
877
|
}
|
|
931
878
|
},
|
|
@@ -933,9 +880,7 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
933
880
|
});
|
|
934
881
|
const handle = {
|
|
935
882
|
batchId: response.id,
|
|
936
|
-
|
|
937
|
-
idempotencyKey: response.idempotencyKey,
|
|
938
|
-
runs: response.runs,
|
|
883
|
+
runCount: response.runCount,
|
|
939
884
|
publicAccessToken: response.publicAccessToken,
|
|
940
885
|
};
|
|
941
886
|
return handle;
|
|
@@ -954,7 +899,7 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
954
899
|
options: {
|
|
955
900
|
dependentAttempt: ctx.attempt.id,
|
|
956
901
|
lockToVersion: v3_1.taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
|
|
957
|
-
queue: options?.queue,
|
|
902
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
958
903
|
concurrencyKey: options?.concurrencyKey,
|
|
959
904
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
960
905
|
payloadType: payloadPacket.dataType,
|
|
@@ -964,7 +909,13 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
964
909
|
maxAttempts: options?.maxAttempts,
|
|
965
910
|
metadata: options?.metadata,
|
|
966
911
|
maxDuration: options?.maxDuration,
|
|
912
|
+
resumeParentOnCompletion: true,
|
|
913
|
+
parentRunId: ctx.run.id,
|
|
914
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
915
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
967
916
|
machine: options?.machine,
|
|
917
|
+
priority: options?.priority,
|
|
918
|
+
releaseConcurrency: options?.releaseConcurrency,
|
|
968
919
|
},
|
|
969
920
|
}, {}, requestOptions);
|
|
970
921
|
span.setAttribute("runId", response.id);
|
|
@@ -996,16 +947,21 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
996
947
|
}
|
|
997
948
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
998
949
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
999
|
-
const response = await apiClient.
|
|
1000
|
-
items: await Promise.all(items.map(async (item) => {
|
|
950
|
+
const response = await apiClient.batchTriggerV3({
|
|
951
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
1001
952
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1002
953
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
954
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1003
955
|
return {
|
|
1004
956
|
task: id,
|
|
1005
957
|
payload: payloadPacket.data,
|
|
1006
958
|
options: {
|
|
1007
959
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1008
|
-
queue: item.options?.queue
|
|
960
|
+
queue: item.options?.queue
|
|
961
|
+
? { name: item.options.queue }
|
|
962
|
+
: queue
|
|
963
|
+
? { name: queue }
|
|
964
|
+
: undefined,
|
|
1009
965
|
concurrencyKey: item.options?.concurrencyKey,
|
|
1010
966
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1011
967
|
payloadType: payloadPacket.dataType,
|
|
@@ -1015,26 +971,24 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1015
971
|
maxAttempts: item.options?.maxAttempts,
|
|
1016
972
|
metadata: item.options?.metadata,
|
|
1017
973
|
maxDuration: item.options?.maxDuration,
|
|
974
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
975
|
+
batchItemIdempotencyKey,
|
|
976
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1018
977
|
machine: item.options?.machine,
|
|
978
|
+
priority: item.options?.priority,
|
|
1019
979
|
},
|
|
1020
980
|
};
|
|
1021
981
|
})),
|
|
1022
|
-
|
|
982
|
+
resumeParentOnCompletion: true,
|
|
983
|
+
parentRunId: ctx.run.id,
|
|
1023
984
|
}, {
|
|
1024
985
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
1025
986
|
}, requestOptions);
|
|
1026
987
|
span.setAttribute("batchId", response.id);
|
|
1027
|
-
span.setAttribute("runCount", response.
|
|
1028
|
-
span.setAttribute("isCached", response.isCached);
|
|
1029
|
-
if (response.isCached) {
|
|
1030
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
1031
|
-
}
|
|
1032
|
-
if (response.idempotencyKey) {
|
|
1033
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
1034
|
-
}
|
|
988
|
+
span.setAttribute("runCount", response.runCount);
|
|
1035
989
|
const result = await v3_1.runtime.waitForBatch({
|
|
1036
990
|
id: response.id,
|
|
1037
|
-
|
|
991
|
+
runCount: response.runCount,
|
|
1038
992
|
ctx,
|
|
1039
993
|
});
|
|
1040
994
|
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
@@ -1114,4 +1068,62 @@ async function handleTaskRunExecutionResult(execution, taskIdentifier) {
|
|
|
1114
1068
|
};
|
|
1115
1069
|
}
|
|
1116
1070
|
}
|
|
1071
|
+
function registerTaskLifecycleHooks(taskId, params) {
|
|
1072
|
+
if (params.init) {
|
|
1073
|
+
v3_1.lifecycleHooks.registerTaskInitHook(taskId, {
|
|
1074
|
+
fn: params.init,
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
if (params.onStart) {
|
|
1078
|
+
v3_1.lifecycleHooks.registerTaskStartHook(taskId, {
|
|
1079
|
+
fn: params.onStart,
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
if (params.onFailure) {
|
|
1083
|
+
v3_1.lifecycleHooks.registerTaskFailureHook(taskId, {
|
|
1084
|
+
fn: params.onFailure,
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
if (params.onSuccess) {
|
|
1088
|
+
v3_1.lifecycleHooks.registerTaskSuccessHook(taskId, {
|
|
1089
|
+
fn: params.onSuccess,
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
if (params.onComplete) {
|
|
1093
|
+
v3_1.lifecycleHooks.registerTaskCompleteHook(taskId, {
|
|
1094
|
+
fn: params.onComplete,
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
if (params.onWait) {
|
|
1098
|
+
v3_1.lifecycleHooks.registerTaskWaitHook(taskId, {
|
|
1099
|
+
fn: params.onWait,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
if (params.onResume) {
|
|
1103
|
+
v3_1.lifecycleHooks.registerTaskResumeHook(taskId, {
|
|
1104
|
+
fn: params.onResume,
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
if (params.catchError) {
|
|
1108
|
+
// We don't need to use an adapter here because catchError is the new version of handleError
|
|
1109
|
+
v3_1.lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1110
|
+
fn: params.catchError,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
if (params.handleError) {
|
|
1114
|
+
v3_1.lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1115
|
+
fn: params.handleError,
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
if (params.middleware) {
|
|
1119
|
+
v3_1.lifecycleHooks.registerTaskMiddlewareHook(taskId, {
|
|
1120
|
+
fn: params.middleware,
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
if (params.cleanup) {
|
|
1124
|
+
v3_1.lifecycleHooks.registerTaskCleanupHook(taskId, {
|
|
1125
|
+
fn: params.cleanup,
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1117
1129
|
//# sourceMappingURL=shared.js.map
|