@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
|
@@ -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,38 +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,
|
|
341
|
+
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
366
342
|
},
|
|
367
343
|
};
|
|
368
344
|
})),
|
|
345
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
369
346
|
}, {
|
|
370
347
|
spanParentAsLink: true,
|
|
371
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
372
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
373
348
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
374
349
|
}, {
|
|
375
350
|
name: "batch.trigger()",
|
|
@@ -380,17 +355,8 @@ async function batchTriggerById(items, options, requestOptions) {
|
|
|
380
355
|
if ("id" in body && typeof body.id === "string") {
|
|
381
356
|
span.setAttribute("batchId", body.id);
|
|
382
357
|
}
|
|
383
|
-
if ("
|
|
384
|
-
span.setAttribute("runCount", body.
|
|
385
|
-
}
|
|
386
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
387
|
-
if (body.isCached) {
|
|
388
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
389
|
-
}
|
|
390
|
-
span.setAttribute("isCached", body.isCached);
|
|
391
|
-
}
|
|
392
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
393
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
358
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
359
|
+
span.setAttribute("runCount", body.runCount);
|
|
394
360
|
}
|
|
395
361
|
}
|
|
396
362
|
},
|
|
@@ -398,9 +364,7 @@ async function batchTriggerById(items, options, requestOptions) {
|
|
|
398
364
|
});
|
|
399
365
|
const handle = {
|
|
400
366
|
batchId: response.id,
|
|
401
|
-
|
|
402
|
-
idempotencyKey: response.idempotencyKey,
|
|
403
|
-
runs: response.runs,
|
|
367
|
+
runCount: response.runCount,
|
|
404
368
|
publicAccessToken: response.publicAccessToken,
|
|
405
369
|
};
|
|
406
370
|
return handle;
|
|
@@ -489,19 +453,20 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
489
453
|
}
|
|
490
454
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
491
455
|
return await tracer_js_1.tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
492
|
-
const response = await apiClient.
|
|
493
|
-
items: await Promise.all(items.map(async (item) => {
|
|
494
|
-
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);
|
|
495
459
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
496
460
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
497
461
|
: item.payload;
|
|
498
462
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
463
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
499
464
|
return {
|
|
500
465
|
task: item.id,
|
|
501
466
|
payload: payloadPacket.data,
|
|
502
467
|
options: {
|
|
503
468
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
504
|
-
queue: item.options?.queue,
|
|
469
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
505
470
|
concurrencyKey: item.options?.concurrencyKey,
|
|
506
471
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
507
472
|
payloadType: payloadPacket.dataType,
|
|
@@ -511,26 +476,24 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
511
476
|
maxAttempts: item.options?.maxAttempts,
|
|
512
477
|
metadata: item.options?.metadata,
|
|
513
478
|
maxDuration: item.options?.maxDuration,
|
|
479
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
480
|
+
batchItemIdempotencyKey,
|
|
481
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
514
482
|
machine: item.options?.machine,
|
|
483
|
+
priority: item.options?.priority,
|
|
515
484
|
},
|
|
516
485
|
};
|
|
517
486
|
})),
|
|
518
|
-
|
|
487
|
+
parentRunId: ctx.run.id,
|
|
488
|
+
resumeParentOnCompletion: true,
|
|
519
489
|
}, {
|
|
520
490
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
521
491
|
}, requestOptions);
|
|
522
492
|
span.setAttribute("batchId", response.id);
|
|
523
|
-
span.setAttribute("runCount", response.
|
|
524
|
-
span.setAttribute("isCached", response.isCached);
|
|
525
|
-
if (response.isCached) {
|
|
526
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
527
|
-
}
|
|
528
|
-
if (response.idempotencyKey) {
|
|
529
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
530
|
-
}
|
|
493
|
+
span.setAttribute("runCount", response.runCount);
|
|
531
494
|
const result = await v3_1.runtime.waitForBatch({
|
|
532
495
|
id: response.id,
|
|
533
|
-
|
|
496
|
+
runCount: response.runCount,
|
|
534
497
|
ctx,
|
|
535
498
|
});
|
|
536
499
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -624,38 +587,39 @@ async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
|
624
587
|
*/
|
|
625
588
|
async function batchTriggerTasks(items, options, requestOptions) {
|
|
626
589
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
627
|
-
const response = await apiClient.
|
|
628
|
-
items: await Promise.all(items.map(async (item) => {
|
|
629
|
-
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);
|
|
630
593
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
631
594
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
632
595
|
: item.payload;
|
|
633
596
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
597
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
634
598
|
return {
|
|
635
599
|
task: item.task.id,
|
|
636
600
|
payload: payloadPacket.data,
|
|
637
601
|
options: {
|
|
638
|
-
queue: item.options?.queue,
|
|
602
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
639
603
|
concurrencyKey: item.options?.concurrencyKey,
|
|
640
604
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
641
605
|
payloadType: payloadPacket.dataType,
|
|
642
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
643
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
644
606
|
delay: item.options?.delay,
|
|
645
607
|
ttl: item.options?.ttl,
|
|
646
608
|
tags: item.options?.tags,
|
|
647
609
|
maxAttempts: item.options?.maxAttempts,
|
|
648
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
649
610
|
metadata: item.options?.metadata,
|
|
650
611
|
maxDuration: item.options?.maxDuration,
|
|
612
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
613
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
651
614
|
machine: item.options?.machine,
|
|
615
|
+
priority: item.options?.priority,
|
|
616
|
+
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
652
617
|
},
|
|
653
618
|
};
|
|
654
619
|
})),
|
|
620
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
655
621
|
}, {
|
|
656
622
|
spanParentAsLink: true,
|
|
657
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
658
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
659
623
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
660
624
|
}, {
|
|
661
625
|
name: "batch.triggerByTask()",
|
|
@@ -666,17 +630,8 @@ async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
666
630
|
if ("id" in body && typeof body.id === "string") {
|
|
667
631
|
span.setAttribute("batchId", body.id);
|
|
668
632
|
}
|
|
669
|
-
if ("
|
|
670
|
-
span.setAttribute("runCount", body.
|
|
671
|
-
}
|
|
672
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
673
|
-
if (body.isCached) {
|
|
674
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
675
|
-
}
|
|
676
|
-
span.setAttribute("isCached", body.isCached);
|
|
677
|
-
}
|
|
678
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
679
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
633
|
+
if ("runCount" in body && typeof body.runCount === "number") {
|
|
634
|
+
span.setAttribute("runCount", body.runCount);
|
|
680
635
|
}
|
|
681
636
|
}
|
|
682
637
|
},
|
|
@@ -684,9 +639,7 @@ async function batchTriggerTasks(items, options, requestOptions) {
|
|
|
684
639
|
});
|
|
685
640
|
const handle = {
|
|
686
641
|
batchId: response.id,
|
|
687
|
-
|
|
688
|
-
idempotencyKey: response.idempotencyKey,
|
|
689
|
-
runs: response.runs,
|
|
642
|
+
runCount: response.runCount,
|
|
690
643
|
publicAccessToken: response.publicAccessToken,
|
|
691
644
|
};
|
|
692
645
|
return handle;
|
|
@@ -775,19 +728,20 @@ async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
775
728
|
}
|
|
776
729
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
777
730
|
return await tracer_js_1.tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
778
|
-
const response = await apiClient.
|
|
779
|
-
items: await Promise.all(items.map(async (item) => {
|
|
780
|
-
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);
|
|
781
734
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
782
735
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
783
736
|
: item.payload;
|
|
784
737
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
738
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
785
739
|
return {
|
|
786
740
|
task: item.task.id,
|
|
787
741
|
payload: payloadPacket.data,
|
|
788
742
|
options: {
|
|
789
743
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
790
|
-
queue: item.options?.queue,
|
|
744
|
+
queue: item.options?.queue ? { name: item.options.queue } : undefined,
|
|
791
745
|
concurrencyKey: item.options?.concurrencyKey,
|
|
792
746
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
793
747
|
payloadType: payloadPacket.dataType,
|
|
@@ -797,26 +751,24 @@ async function batchTriggerAndWaitTasks(items, options, requestOptions) {
|
|
|
797
751
|
maxAttempts: item.options?.maxAttempts,
|
|
798
752
|
metadata: item.options?.metadata,
|
|
799
753
|
maxDuration: item.options?.maxDuration,
|
|
754
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
755
|
+
batchItemIdempotencyKey,
|
|
756
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
800
757
|
machine: item.options?.machine,
|
|
758
|
+
priority: item.options?.priority,
|
|
801
759
|
},
|
|
802
760
|
};
|
|
803
761
|
})),
|
|
804
|
-
|
|
762
|
+
parentRunId: ctx.run.id,
|
|
763
|
+
resumeParentOnCompletion: true,
|
|
805
764
|
}, {
|
|
806
765
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
807
766
|
}, requestOptions);
|
|
808
767
|
span.setAttribute("batchId", response.id);
|
|
809
|
-
span.setAttribute("runCount", response.
|
|
810
|
-
span.setAttribute("isCached", response.isCached);
|
|
811
|
-
if (response.isCached) {
|
|
812
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
813
|
-
}
|
|
814
|
-
if (response.idempotencyKey) {
|
|
815
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
816
|
-
}
|
|
768
|
+
span.setAttribute("runCount", response.runCount);
|
|
817
769
|
const result = await v3_1.runtime.waitForBatch({
|
|
818
770
|
id: response.id,
|
|
819
|
-
|
|
771
|
+
runCount: response.runCount,
|
|
820
772
|
ctx,
|
|
821
773
|
});
|
|
822
774
|
const runs = await handleBatchTaskRunExecutionResultV2(result.items);
|
|
@@ -838,7 +790,7 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
838
790
|
const handle = await apiClient.triggerTask(id, {
|
|
839
791
|
payload: payloadPacket.data,
|
|
840
792
|
options: {
|
|
841
|
-
queue: options?.queue,
|
|
793
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
842
794
|
concurrencyKey: options?.concurrencyKey,
|
|
843
795
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
844
796
|
payloadType: payloadPacket.dataType,
|
|
@@ -848,10 +800,12 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
848
800
|
ttl: options?.ttl,
|
|
849
801
|
tags: options?.tags,
|
|
850
802
|
maxAttempts: options?.maxAttempts,
|
|
851
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
852
803
|
metadata: options?.metadata,
|
|
853
804
|
maxDuration: options?.maxDuration,
|
|
805
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
854
806
|
machine: options?.machine,
|
|
807
|
+
priority: options?.priority,
|
|
808
|
+
lockToVersion: options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
855
809
|
},
|
|
856
810
|
}, {
|
|
857
811
|
spanParentAsLink: true,
|
|
@@ -872,35 +826,41 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
872
826
|
}
|
|
873
827
|
async function batchTrigger_internal(name, taskIdentifier, items, options, parsePayload, requestOptions, queue) {
|
|
874
828
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
875
|
-
const
|
|
876
|
-
|
|
829
|
+
const ctx = v3_1.taskContext.ctx;
|
|
830
|
+
const response = await apiClient.batchTriggerV3({
|
|
831
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
877
832
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
878
833
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
834
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
879
835
|
return {
|
|
880
836
|
task: taskIdentifier,
|
|
881
837
|
payload: payloadPacket.data,
|
|
882
838
|
options: {
|
|
883
|
-
queue: item.options?.queue
|
|
839
|
+
queue: item.options?.queue
|
|
840
|
+
? { name: item.options.queue }
|
|
841
|
+
: queue
|
|
842
|
+
? { name: queue }
|
|
843
|
+
: undefined,
|
|
884
844
|
concurrencyKey: item.options?.concurrencyKey,
|
|
885
845
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
886
846
|
payloadType: payloadPacket.dataType,
|
|
887
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
888
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
889
847
|
delay: item.options?.delay,
|
|
890
848
|
ttl: item.options?.ttl,
|
|
891
849
|
tags: item.options?.tags,
|
|
892
850
|
maxAttempts: item.options?.maxAttempts,
|
|
893
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
894
851
|
metadata: item.options?.metadata,
|
|
895
852
|
maxDuration: item.options?.maxDuration,
|
|
853
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
854
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
896
855
|
machine: item.options?.machine,
|
|
856
|
+
priority: item.options?.priority,
|
|
857
|
+
lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
|
|
897
858
|
},
|
|
898
859
|
};
|
|
899
860
|
})),
|
|
861
|
+
parentRunId: ctx?.run.id,
|
|
900
862
|
}, {
|
|
901
863
|
spanParentAsLink: true,
|
|
902
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
903
|
-
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
904
864
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
905
865
|
}, {
|
|
906
866
|
name,
|
|
@@ -911,17 +871,8 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
911
871
|
if ("id" in body && typeof body.id === "string") {
|
|
912
872
|
span.setAttribute("batchId", body.id);
|
|
913
873
|
}
|
|
914
|
-
if ("
|
|
915
|
-
span.setAttribute("runCount", body.
|
|
916
|
-
}
|
|
917
|
-
if ("isCached" in body && typeof body.isCached === "boolean") {
|
|
918
|
-
if (body.isCached) {
|
|
919
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
920
|
-
}
|
|
921
|
-
span.setAttribute("isCached", body.isCached);
|
|
922
|
-
}
|
|
923
|
-
if ("idempotencyKey" in body && typeof body.idempotencyKey === "string") {
|
|
924
|
-
span.setAttribute("idempotencyKey", body.idempotencyKey);
|
|
874
|
+
if ("runCount" in body && Array.isArray(body.runCount)) {
|
|
875
|
+
span.setAttribute("runCount", body.runCount);
|
|
925
876
|
}
|
|
926
877
|
}
|
|
927
878
|
},
|
|
@@ -929,9 +880,7 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
929
880
|
});
|
|
930
881
|
const handle = {
|
|
931
882
|
batchId: response.id,
|
|
932
|
-
|
|
933
|
-
idempotencyKey: response.idempotencyKey,
|
|
934
|
-
runs: response.runs,
|
|
883
|
+
runCount: response.runCount,
|
|
935
884
|
publicAccessToken: response.publicAccessToken,
|
|
936
885
|
};
|
|
937
886
|
return handle;
|
|
@@ -950,7 +899,7 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
950
899
|
options: {
|
|
951
900
|
dependentAttempt: ctx.attempt.id,
|
|
952
901
|
lockToVersion: v3_1.taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
|
|
953
|
-
queue: options?.queue,
|
|
902
|
+
queue: options?.queue ? { name: options.queue } : undefined,
|
|
954
903
|
concurrencyKey: options?.concurrencyKey,
|
|
955
904
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
956
905
|
payloadType: payloadPacket.dataType,
|
|
@@ -960,7 +909,13 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
960
909
|
maxAttempts: options?.maxAttempts,
|
|
961
910
|
metadata: options?.metadata,
|
|
962
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,
|
|
963
916
|
machine: options?.machine,
|
|
917
|
+
priority: options?.priority,
|
|
918
|
+
releaseConcurrency: options?.releaseConcurrency,
|
|
964
919
|
},
|
|
965
920
|
}, {}, requestOptions);
|
|
966
921
|
span.setAttribute("runId", response.id);
|
|
@@ -992,16 +947,21 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
992
947
|
}
|
|
993
948
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
994
949
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
995
|
-
const response = await apiClient.
|
|
996
|
-
items: await Promise.all(items.map(async (item) => {
|
|
950
|
+
const response = await apiClient.batchTriggerV3({
|
|
951
|
+
items: await Promise.all(items.map(async (item, index) => {
|
|
997
952
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
998
953
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
954
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
999
955
|
return {
|
|
1000
956
|
task: id,
|
|
1001
957
|
payload: payloadPacket.data,
|
|
1002
958
|
options: {
|
|
1003
959
|
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1004
|
-
queue: item.options?.queue
|
|
960
|
+
queue: item.options?.queue
|
|
961
|
+
? { name: item.options.queue }
|
|
962
|
+
: queue
|
|
963
|
+
? { name: queue }
|
|
964
|
+
: undefined,
|
|
1005
965
|
concurrencyKey: item.options?.concurrencyKey,
|
|
1006
966
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1007
967
|
payloadType: payloadPacket.dataType,
|
|
@@ -1011,26 +971,24 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1011
971
|
maxAttempts: item.options?.maxAttempts,
|
|
1012
972
|
metadata: item.options?.metadata,
|
|
1013
973
|
maxDuration: item.options?.maxDuration,
|
|
974
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ??
|
|
975
|
+
batchItemIdempotencyKey,
|
|
976
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1014
977
|
machine: item.options?.machine,
|
|
978
|
+
priority: item.options?.priority,
|
|
1015
979
|
},
|
|
1016
980
|
};
|
|
1017
981
|
})),
|
|
1018
|
-
|
|
982
|
+
resumeParentOnCompletion: true,
|
|
983
|
+
parentRunId: ctx.run.id,
|
|
1019
984
|
}, {
|
|
1020
985
|
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
1021
986
|
}, requestOptions);
|
|
1022
987
|
span.setAttribute("batchId", response.id);
|
|
1023
|
-
span.setAttribute("runCount", response.
|
|
1024
|
-
span.setAttribute("isCached", response.isCached);
|
|
1025
|
-
if (response.isCached) {
|
|
1026
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
1027
|
-
}
|
|
1028
|
-
if (response.idempotencyKey) {
|
|
1029
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
1030
|
-
}
|
|
988
|
+
span.setAttribute("runCount", response.runCount);
|
|
1031
989
|
const result = await v3_1.runtime.waitForBatch({
|
|
1032
990
|
id: response.id,
|
|
1033
|
-
|
|
991
|
+
runCount: response.runCount,
|
|
1034
992
|
ctx,
|
|
1035
993
|
});
|
|
1036
994
|
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
@@ -1110,4 +1068,62 @@ async function handleTaskRunExecutionResult(execution, taskIdentifier) {
|
|
|
1110
1068
|
};
|
|
1111
1069
|
}
|
|
1112
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
|
+
}
|
|
1113
1129
|
//# sourceMappingURL=shared.js.map
|