@trigger.dev/core 0.0.0-v3-schedules-beta-20240417141912 → 0.0.0-v3-prelease-20240419151535
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 +72 -42
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +73 -43
- 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,10 +3873,9 @@ 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", {
|
|
@@ -3858,8 +3893,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3858
3893
|
const promise = Promise.all(params.runs.map((runId) => {
|
|
3859
3894
|
return new Promise((resolve, reject) => {
|
|
3860
3895
|
this._taskWaits.set(runId, {
|
|
3861
|
-
resolve
|
|
3862
|
-
reject
|
|
3896
|
+
resolve
|
|
3863
3897
|
});
|
|
3864
3898
|
});
|
|
3865
3899
|
}));
|
|
@@ -3878,11 +3912,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
|
|
|
3878
3912
|
if (!wait) {
|
|
3879
3913
|
return;
|
|
3880
3914
|
}
|
|
3881
|
-
|
|
3882
|
-
wait.resolve(completion);
|
|
3883
|
-
} else {
|
|
3884
|
-
wait.reject(completion);
|
|
3885
|
-
}
|
|
3915
|
+
wait.resolve(completion);
|
|
3886
3916
|
this._taskWaits.delete(execution.run.id);
|
|
3887
3917
|
}
|
|
3888
3918
|
get waitThresholdInMs() {
|
|
@@ -4771,7 +4801,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4771
4801
|
}
|
|
4772
4802
|
return {
|
|
4773
4803
|
ok: true,
|
|
4774
|
-
id: execution.
|
|
4804
|
+
id: execution.run.id,
|
|
4775
4805
|
output: finalOutput.data,
|
|
4776
4806
|
outputType: finalOutput.dataType
|
|
4777
4807
|
};
|
|
@@ -4779,7 +4809,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4779
4809
|
recordSpanException(span, stringifyError);
|
|
4780
4810
|
return {
|
|
4781
4811
|
ok: false,
|
|
4782
|
-
id: execution.
|
|
4812
|
+
id: execution.run.id,
|
|
4783
4813
|
error: {
|
|
4784
4814
|
type: "INTERNAL_ERROR",
|
|
4785
4815
|
code: TaskRunErrorCodes.TASK_OUTPUT_ERROR,
|
|
@@ -4792,7 +4822,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4792
4822
|
const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
|
|
4793
4823
|
recordSpanException(span, handleErrorResult.error ?? runError);
|
|
4794
4824
|
return {
|
|
4795
|
-
id: execution.
|
|
4825
|
+
id: execution.run.id,
|
|
4796
4826
|
ok: false,
|
|
4797
4827
|
error: handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError),
|
|
4798
4828
|
retry: handleErrorResult.status === "retry" ? handleErrorResult.retry : void 0,
|
|
@@ -4802,7 +4832,7 @@ var _TaskExecutor = class _TaskExecutor {
|
|
|
4802
4832
|
recordSpanException(span, handleErrorError);
|
|
4803
4833
|
return {
|
|
4804
4834
|
ok: false,
|
|
4805
|
-
id: execution.
|
|
4835
|
+
id: execution.run.id,
|
|
4806
4836
|
error: {
|
|
4807
4837
|
type: "INTERNAL_ERROR",
|
|
4808
4838
|
code: TaskRunErrorCodes.HANDLE_ERROR_ERROR,
|