@trigger.dev/core 3.0.0-beta.13 → 3.0.0-beta.15
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/v3/index.d.mts +1129 -951
- package/dist/v3/index.d.ts +1129 -951
- package/dist/v3/index.js +76 -43
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +77 -44
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/otel/index.js +4 -2
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +4 -2
- package/dist/v3/otel/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/v3/index.js
CHANGED
|
@@ -100,7 +100,8 @@ var TaskRunErrorCodes = {
|
|
|
100
100
|
TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE: "TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
|
|
101
101
|
TASK_RUN_CANCELLED: "TASK_RUN_CANCELLED",
|
|
102
102
|
TASK_OUTPUT_ERROR: "TASK_OUTPUT_ERROR",
|
|
103
|
-
HANDLE_ERROR_ERROR: "HANDLE_ERROR_ERROR"
|
|
103
|
+
HANDLE_ERROR_ERROR: "HANDLE_ERROR_ERROR",
|
|
104
|
+
GRACEFUL_EXIT_TIMEOUT: "GRACEFUL_EXIT_TIMEOUT"
|
|
104
105
|
};
|
|
105
106
|
var TaskRunInternalError = zod.z.object({
|
|
106
107
|
type: zod.z.literal("INTERNAL_ERROR"),
|
|
@@ -114,7 +115,8 @@ var TaskRunInternalError = zod.z.object({
|
|
|
114
115
|
"TASK_PROCESS_EXITED_WITH_NON_ZERO_CODE",
|
|
115
116
|
"TASK_RUN_CANCELLED",
|
|
116
117
|
"TASK_OUTPUT_ERROR",
|
|
117
|
-
"HANDLE_ERROR_ERROR"
|
|
118
|
+
"HANDLE_ERROR_ERROR",
|
|
119
|
+
"GRACEFUL_EXIT_TIMEOUT"
|
|
118
120
|
]),
|
|
119
121
|
message: zod.z.string().optional()
|
|
120
122
|
});
|
|
@@ -131,7 +133,8 @@ var TaskRun = zod.z.object({
|
|
|
131
133
|
context: zod.z.any(),
|
|
132
134
|
tags: zod.z.array(zod.z.string()),
|
|
133
135
|
isTest: zod.z.boolean().default(false),
|
|
134
|
-
createdAt: zod.z.coerce.date()
|
|
136
|
+
createdAt: zod.z.coerce.date(),
|
|
137
|
+
idempotencyKey: zod.z.string().optional()
|
|
135
138
|
});
|
|
136
139
|
var TaskRunExecutionTask = zod.z.object({
|
|
137
140
|
id: zod.z.string(),
|
|
@@ -2067,7 +2070,8 @@ var SemanticInternalAttributes = {
|
|
|
2067
2070
|
RETRY_AT: "retry.at",
|
|
2068
2071
|
RETRY_DELAY: "retry.delay",
|
|
2069
2072
|
RETRY_COUNT: "retry.count",
|
|
2070
|
-
LINK_TITLE: "$link.title"
|
|
2073
|
+
LINK_TITLE: "$link.title",
|
|
2074
|
+
IDEMPOTENCY_KEY: "ctx.run.idempotencyKey"
|
|
2071
2075
|
};
|
|
2072
2076
|
|
|
2073
2077
|
// src/v3/tasks/taskContextManager.ts
|
|
@@ -2126,7 +2130,8 @@ var _TaskContextManager = class _TaskContextManager {
|
|
|
2126
2130
|
[SemanticInternalAttributes.RUN_IS_TEST]: this.ctx.run.isTest,
|
|
2127
2131
|
[SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
|
|
2128
2132
|
[SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
|
|
2129
|
-
[SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id
|
|
2133
|
+
[SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id,
|
|
2134
|
+
[SemanticInternalAttributes.IDEMPOTENCY_KEY]: this.ctx.run.idempotencyKey
|
|
2130
2135
|
};
|
|
2131
2136
|
}
|
|
2132
2137
|
return {};
|
|
@@ -2217,6 +2222,27 @@ var _ApiClient = class _ApiClient {
|
|
|
2217
2222
|
this.accessToken = accessToken;
|
|
2218
2223
|
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
2219
2224
|
}
|
|
2225
|
+
async getRunResult(runId) {
|
|
2226
|
+
try {
|
|
2227
|
+
return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
|
|
2228
|
+
method: "GET",
|
|
2229
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
2230
|
+
}, zodFetchOptions);
|
|
2231
|
+
} catch (error) {
|
|
2232
|
+
if (error instanceof APIError) {
|
|
2233
|
+
if (error.status === 404) {
|
|
2234
|
+
return void 0;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
throw error;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
async getBatchResults(batchId) {
|
|
2241
|
+
return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
|
|
2242
|
+
method: "GET",
|
|
2243
|
+
headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
|
|
2244
|
+
}, zodFetchOptions);
|
|
2245
|
+
}
|
|
2220
2246
|
triggerTask(taskId, body, options) {
|
|
2221
2247
|
return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/trigger`, {
|
|
2222
2248
|
method: "POST",
|
|
@@ -3462,12 +3488,23 @@ __name(_NoopTaskLogger, "NoopTaskLogger");
|
|
|
3462
3488
|
var NoopTaskLogger = _NoopTaskLogger;
|
|
3463
3489
|
function safeJsonProcess(value) {
|
|
3464
3490
|
try {
|
|
3465
|
-
return JSON.parse(JSON.stringify(value));
|
|
3491
|
+
return JSON.parse(JSON.stringify(value, jsonErrorReplacer));
|
|
3466
3492
|
} catch {
|
|
3467
3493
|
return value;
|
|
3468
3494
|
}
|
|
3469
3495
|
}
|
|
3470
3496
|
__name(safeJsonProcess, "safeJsonProcess");
|
|
3497
|
+
function jsonErrorReplacer(key, value) {
|
|
3498
|
+
if (value instanceof Error) {
|
|
3499
|
+
return {
|
|
3500
|
+
name: value.name,
|
|
3501
|
+
message: value.message,
|
|
3502
|
+
stack: value.stack
|
|
3503
|
+
};
|
|
3504
|
+
}
|
|
3505
|
+
return value;
|
|
3506
|
+
}
|
|
3507
|
+
__name(jsonErrorReplacer, "jsonErrorReplacer");
|
|
3471
3508
|
|
|
3472
3509
|
// src/v3/logger/index.ts
|
|
3473
3510
|
var API_NAME3 = "logger";
|
|
@@ -3707,6 +3744,17 @@ function formatDurationInDays(milliseconds) {
|
|
|
3707
3744
|
return duration;
|
|
3708
3745
|
}
|
|
3709
3746
|
__name(formatDurationInDays, "formatDurationInDays");
|
|
3747
|
+
async function unboundedTimeout(delay = 0, value, options) {
|
|
3748
|
+
const maxDelay = 2147483647;
|
|
3749
|
+
const fullTimeouts = Math.floor(delay / maxDelay);
|
|
3750
|
+
const remainingDelay = delay % maxDelay;
|
|
3751
|
+
let lastTimeoutResult = await promises.setTimeout(remainingDelay, value, options);
|
|
3752
|
+
for (let i = 0; i < fullTimeouts; i++) {
|
|
3753
|
+
lastTimeoutResult = await promises.setTimeout(maxDelay, value, options);
|
|
3754
|
+
}
|
|
3755
|
+
return lastTimeoutResult;
|
|
3756
|
+
}
|
|
3757
|
+
__name(unboundedTimeout, "unboundedTimeout");
|
|
3710
3758
|
|
|
3711
3759
|
// src/v3/runtime/devRuntimeManager.ts
|
|
3712
3760
|
var _DevRuntimeManager = class _DevRuntimeManager {
|
|
@@ -3718,14 +3766,10 @@ var _DevRuntimeManager = class _DevRuntimeManager {
|
|
|
3718
3766
|
disable() {
|
|
3719
3767
|
}
|
|
3720
3768
|
async waitForDuration(ms) {
|
|
3721
|
-
|
|
3722
|
-
setTimeout(resolve, ms);
|
|
3723
|
-
});
|
|
3769
|
+
await unboundedTimeout(ms);
|
|
3724
3770
|
}
|
|
3725
3771
|
async waitUntil(date) {
|
|
3726
|
-
return
|
|
3727
|
-
setTimeout(resolve, date.getTime() - Date.now());
|
|
3728
|
-
});
|
|
3772
|
+
return this.waitForDuration(date.getTime() - Date.now());
|
|
3729
3773
|
}
|
|
3730
3774
|
async waitForTask(params) {
|
|
3731
3775
|
const pendingCompletion = this._pendingCompletionNotifications.get(params.id);
|
|
@@ -3733,10 +3777,9 @@ var _DevRuntimeManager = class _DevRuntimeManager {
|
|
|
3733
3777
|
this._pendingCompletionNotifications.delete(params.id);
|
|
3734
3778
|
return pendingCompletion;
|
|
3735
3779
|
}
|
|
3736
|
-
const promise = new Promise((resolve
|
|
3780
|
+
const promise = new Promise((resolve) => {
|
|
3737
3781
|
this._taskWaits.set(params.id, {
|
|
3738
|
-
resolve
|
|
3739
|
-
reject
|
|
3782
|
+
resolve
|
|
3740
3783
|
});
|
|
3741
3784
|
});
|
|
3742
3785
|
return await promise;
|
|
@@ -3753,16 +3796,11 @@ var _DevRuntimeManager = class _DevRuntimeManager {
|
|
|
3753
3796
|
const pendingCompletion = this._pendingCompletionNotifications.get(runId);
|
|
3754
3797
|
if (pendingCompletion) {
|
|
3755
3798
|
this._pendingCompletionNotifications.delete(runId);
|
|
3756
|
-
|
|
3757
|
-
resolve(pendingCompletion);
|
|
3758
|
-
} else {
|
|
3759
|
-
reject(pendingCompletion);
|
|
3760
|
-
}
|
|
3799
|
+
resolve(pendingCompletion);
|
|
3761
3800
|
return;
|
|
3762
3801
|
}
|
|
3763
3802
|
this._taskWaits.set(runId, {
|
|
3764
|
-
resolve
|
|
3765
|
-
reject
|
|
3803
|
+
resolve
|
|
3766
3804
|
});
|
|
3767
3805
|
});
|
|
3768
3806
|
}));
|
|
@@ -3778,16 +3816,14 @@ var _DevRuntimeManager = class _DevRuntimeManager {
|
|
|
3778
3816
|
this._pendingCompletionNotifications.set(execution.run.id, completion);
|
|
3779
3817
|
return;
|
|
3780
3818
|
}
|
|
3781
|
-
|
|
3782
|
-
wait.resolve(completion);
|
|
3783
|
-
} else {
|
|
3784
|
-
wait.reject(completion);
|
|
3785
|
-
}
|
|
3819
|
+
wait.resolve(completion);
|
|
3786
3820
|
this._taskWaits.delete(execution.run.id);
|
|
3787
3821
|
}
|
|
3788
3822
|
};
|
|
3789
3823
|
__name(_DevRuntimeManager, "DevRuntimeManager");
|
|
3790
3824
|
var DevRuntimeManager = _DevRuntimeManager;
|
|
3825
|
+
|
|
3826
|
+
// src/v3/runtime/prodRuntimeManager.ts
|
|
3791
3827
|
var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
3792
3828
|
constructor(ipc, options = {}) {
|
|
3793
3829
|
this.ipc = ipc;
|
|
@@ -3799,7 +3835,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3799
3835
|
}
|
|
3800
3836
|
async waitForDuration(ms) {
|
|
3801
3837
|
const now = Date.now();
|
|
3802
|
-
const resolveAfterDuration =
|
|
3838
|
+
const resolveAfterDuration = unboundedTimeout(ms, "duration");
|
|
3803
3839
|
if (ms <= this.waitThresholdInMs) {
|
|
3804
3840
|
await resolveAfterDuration;
|
|
3805
3841
|
return;
|
|
@@ -3837,16 +3873,17 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3837
3873
|
return this.waitForDuration(date.getTime() - Date.now());
|
|
3838
3874
|
}
|
|
3839
3875
|
async waitForTask(params) {
|
|
3840
|
-
const promise = new Promise((resolve
|
|
3876
|
+
const promise = new Promise((resolve) => {
|
|
3841
3877
|
this._taskWaits.set(params.id, {
|
|
3842
|
-
resolve
|
|
3843
|
-
reject
|
|
3878
|
+
resolve
|
|
3844
3879
|
});
|
|
3845
3880
|
});
|
|
3846
3881
|
await this.ipc.send("WAIT_FOR_TASK", {
|
|
3847
3882
|
friendlyId: params.id
|
|
3848
3883
|
});
|
|
3849
|
-
|
|
3884
|
+
const result = await promise;
|
|
3885
|
+
clock.reset();
|
|
3886
|
+
return result;
|
|
3850
3887
|
}
|
|
3851
3888
|
async waitForBatch(params) {
|
|
3852
3889
|
if (!params.runs.length) {
|
|
@@ -3858,8 +3895,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3858
3895
|
const promise = Promise.all(params.runs.map((runId) => {
|
|
3859
3896
|
return new Promise((resolve, reject) => {
|
|
3860
3897
|
this._taskWaits.set(runId, {
|
|
3861
|
-
resolve
|
|
3862
|
-
reject
|
|
3898
|
+
resolve
|
|
3863
3899
|
});
|
|
3864
3900
|
});
|
|
3865
3901
|
}));
|
|
@@ -3868,6 +3904,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3868
3904
|
runFriendlyIds: params.runs
|
|
3869
3905
|
});
|
|
3870
3906
|
const results = await promise;
|
|
3907
|
+
clock.reset();
|
|
3871
3908
|
return {
|
|
3872
3909
|
id: params.id,
|
|
3873
3910
|
items: results
|
|
@@ -3878,11 +3915,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3878
3915
|
if (!wait) {
|
|
3879
3916
|
return;
|
|
3880
3917
|
}
|
|
3881
|
-
|
|
3882
|
-
wait.resolve(completion);
|
|
3883
|
-
} else {
|
|
3884
|
-
wait.reject(completion);
|
|
3885
|
-
}
|
|
3918
|
+
wait.resolve(completion);
|
|
3886
3919
|
this._taskWaits.delete(execution.run.id);
|
|
3887
3920
|
}
|
|
3888
3921
|
get waitThresholdInMs() {
|
|
@@ -4771,7 +4804,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4771
4804
|
}
|
|
4772
4805
|
return {
|
|
4773
4806
|
ok: true,
|
|
4774
|
-
id: execution.
|
|
4807
|
+
id: execution.run.id,
|
|
4775
4808
|
output: finalOutput.data,
|
|
4776
4809
|
outputType: finalOutput.dataType
|
|
4777
4810
|
};
|
|
@@ -4779,7 +4812,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4779
4812
|
recordSpanException(span, stringifyError);
|
|
4780
4813
|
return {
|
|
4781
4814
|
ok: false,
|
|
4782
|
-
id: execution.
|
|
4815
|
+
id: execution.run.id,
|
|
4783
4816
|
error: {
|
|
4784
4817
|
type: "INTERNAL_ERROR",
|
|
4785
4818
|
code: TaskRunErrorCodes.TASK_OUTPUT_ERROR,
|
|
@@ -4792,7 +4825,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4792
4825
|
const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
|
|
4793
4826
|
recordSpanException(span, handleErrorResult.error ?? runError);
|
|
4794
4827
|
return {
|
|
4795
|
-
id: execution.
|
|
4828
|
+
id: execution.run.id,
|
|
4796
4829
|
ok: false,
|
|
4797
4830
|
error: handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError),
|
|
4798
4831
|
retry: handleErrorResult.status === "retry" ? handleErrorResult.retry : void 0,
|
|
@@ -4802,7 +4835,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4802
4835
|
recordSpanException(span, handleErrorError);
|
|
4803
4836
|
return {
|
|
4804
4837
|
ok: false,
|
|
4805
|
-
id: execution.
|
|
4838
|
+
id: execution.run.id,
|
|
4806
4839
|
error: {
|
|
4807
4840
|
type: "INTERNAL_ERROR",
|
|
4808
4841
|
code: TaskRunErrorCodes.HANDLE_ERROR_ERROR,
|