trigger.dev 3.0.0-beta.34 → 3.0.0-beta.35
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/index.js +453 -200
- package/dist/index.js.map +1 -1
- package/dist/workers/dev/worker-facade.js +12 -3
- package/dist/workers/dev/worker-setup.js +1 -1
- package/dist/workers/prod/entry-point.js +522 -193
- package/dist/workers/prod/worker-facade.js +3 -17
- package/dist/workers/prod/worker-setup.js +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -799,7 +799,7 @@ import invariant from "tiny-invariant";
|
|
|
799
799
|
import { z as z4 } from "zod";
|
|
800
800
|
|
|
801
801
|
// package.json
|
|
802
|
-
var version = "3.0.0-beta.
|
|
802
|
+
var version = "3.0.0-beta.35";
|
|
803
803
|
var dependencies = {
|
|
804
804
|
"@anatine/esbuild-decorators": "^0.2.19",
|
|
805
805
|
"@clack/prompts": "^0.7.0",
|
|
@@ -816,7 +816,7 @@ var dependencies = {
|
|
|
816
816
|
"@opentelemetry/sdk-trace-base": "^1.22.0",
|
|
817
817
|
"@opentelemetry/sdk-trace-node": "^1.22.0",
|
|
818
818
|
"@opentelemetry/semantic-conventions": "^1.22.0",
|
|
819
|
-
"@trigger.dev/core": "workspace:3.0.0-beta.
|
|
819
|
+
"@trigger.dev/core": "workspace:3.0.0-beta.35",
|
|
820
820
|
"@types/degit": "^2.8.3",
|
|
821
821
|
chalk: "^5.2.0",
|
|
822
822
|
chokidar: "^3.5.3",
|
|
@@ -949,8 +949,11 @@ import {
|
|
|
949
949
|
GetDeploymentResponseBody,
|
|
950
950
|
GetProjectsResponseBody,
|
|
951
951
|
GetProjectResponseBody,
|
|
952
|
-
EnvironmentVariableResponseBody
|
|
952
|
+
EnvironmentVariableResponseBody,
|
|
953
|
+
TaskRunExecution,
|
|
954
|
+
APIError
|
|
953
955
|
} from "@trigger.dev/core/v3";
|
|
956
|
+
import { zodfetch } from "@trigger.dev/core/v3/zodfetch";
|
|
954
957
|
var CliApiClient = class {
|
|
955
958
|
constructor(apiURL, accessToken) {
|
|
956
959
|
this.accessToken = accessToken;
|
|
@@ -958,7 +961,7 @@ var CliApiClient = class {
|
|
|
958
961
|
}
|
|
959
962
|
apiURL;
|
|
960
963
|
async createAuthorizationCode() {
|
|
961
|
-
return
|
|
964
|
+
return wrapZodFetch(
|
|
962
965
|
CreateAuthorizationCodeResponseSchema,
|
|
963
966
|
`${this.apiURL}/api/v1/authorization-code`,
|
|
964
967
|
{
|
|
@@ -967,7 +970,7 @@ var CliApiClient = class {
|
|
|
967
970
|
);
|
|
968
971
|
}
|
|
969
972
|
async getPersonalAccessToken(authorizationCode) {
|
|
970
|
-
return
|
|
973
|
+
return wrapZodFetch(GetPersonalAccessTokenResponseSchema, `${this.apiURL}/api/v1/token`, {
|
|
971
974
|
method: "POST",
|
|
972
975
|
body: JSON.stringify({
|
|
973
976
|
authorizationCode
|
|
@@ -978,7 +981,7 @@ var CliApiClient = class {
|
|
|
978
981
|
if (!this.accessToken) {
|
|
979
982
|
throw new Error("whoAmI: No access token");
|
|
980
983
|
}
|
|
981
|
-
return
|
|
984
|
+
return wrapZodFetch(WhoAmIResponseSchema, `${this.apiURL}/api/v2/whoami`, {
|
|
982
985
|
headers: {
|
|
983
986
|
Authorization: `Bearer ${this.accessToken}`,
|
|
984
987
|
"Content-Type": "application/json"
|
|
@@ -989,7 +992,7 @@ var CliApiClient = class {
|
|
|
989
992
|
if (!this.accessToken) {
|
|
990
993
|
throw new Error("getProject: No access token");
|
|
991
994
|
}
|
|
992
|
-
return
|
|
995
|
+
return wrapZodFetch(GetProjectResponseBody, `${this.apiURL}/api/v1/projects/${projectRef}`, {
|
|
993
996
|
headers: {
|
|
994
997
|
Authorization: `Bearer ${this.accessToken}`,
|
|
995
998
|
"Content-Type": "application/json"
|
|
@@ -1000,7 +1003,7 @@ var CliApiClient = class {
|
|
|
1000
1003
|
if (!this.accessToken) {
|
|
1001
1004
|
throw new Error("getProjects: No access token");
|
|
1002
1005
|
}
|
|
1003
|
-
return
|
|
1006
|
+
return wrapZodFetch(GetProjectsResponseBody, `${this.apiURL}/api/v1/projects`, {
|
|
1004
1007
|
headers: {
|
|
1005
1008
|
Authorization: `Bearer ${this.accessToken}`,
|
|
1006
1009
|
"Content-Type": "application/json"
|
|
@@ -1011,7 +1014,7 @@ var CliApiClient = class {
|
|
|
1011
1014
|
if (!this.accessToken) {
|
|
1012
1015
|
throw new Error("createBackgroundWorker: No access token");
|
|
1013
1016
|
}
|
|
1014
|
-
return
|
|
1017
|
+
return wrapZodFetch(
|
|
1015
1018
|
CreateBackgroundWorkerResponse,
|
|
1016
1019
|
`${this.apiURL}/api/v1/projects/${projectRef}/background-workers`,
|
|
1017
1020
|
{
|
|
@@ -1024,6 +1027,18 @@ var CliApiClient = class {
|
|
|
1024
1027
|
}
|
|
1025
1028
|
);
|
|
1026
1029
|
}
|
|
1030
|
+
async createTaskRunAttempt(runFriendlyId) {
|
|
1031
|
+
if (!this.accessToken) {
|
|
1032
|
+
throw new Error("creatTaskRunAttempt: No access token");
|
|
1033
|
+
}
|
|
1034
|
+
return wrapZodFetch(TaskRunExecution, `${this.apiURL}/api/v1/runs/${runFriendlyId}/attempts`, {
|
|
1035
|
+
method: "POST",
|
|
1036
|
+
headers: {
|
|
1037
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1038
|
+
"Content-Type": "application/json"
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1027
1042
|
async getProjectEnv({
|
|
1028
1043
|
projectRef,
|
|
1029
1044
|
env
|
|
@@ -1031,18 +1046,22 @@ var CliApiClient = class {
|
|
|
1031
1046
|
if (!this.accessToken) {
|
|
1032
1047
|
throw new Error("getProjectDevEnv: No access token");
|
|
1033
1048
|
}
|
|
1034
|
-
return
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1049
|
+
return wrapZodFetch(
|
|
1050
|
+
GetProjectEnvResponse,
|
|
1051
|
+
`${this.apiURL}/api/v1/projects/${projectRef}/${env}`,
|
|
1052
|
+
{
|
|
1053
|
+
headers: {
|
|
1054
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
1055
|
+
"Content-Type": "application/json"
|
|
1056
|
+
}
|
|
1038
1057
|
}
|
|
1039
|
-
|
|
1058
|
+
);
|
|
1040
1059
|
}
|
|
1041
1060
|
async getEnvironmentVariables(projectRef) {
|
|
1042
1061
|
if (!this.accessToken) {
|
|
1043
1062
|
throw new Error("getEnvironmentVariables: No access token");
|
|
1044
1063
|
}
|
|
1045
|
-
return
|
|
1064
|
+
return wrapZodFetch(
|
|
1046
1065
|
GetEnvironmentVariablesResponseBody,
|
|
1047
1066
|
`${this.apiURL}/api/v1/projects/${projectRef}/envvars`,
|
|
1048
1067
|
{
|
|
@@ -1057,7 +1076,7 @@ var CliApiClient = class {
|
|
|
1057
1076
|
if (!this.accessToken) {
|
|
1058
1077
|
throw new Error("importEnvVars: No access token");
|
|
1059
1078
|
}
|
|
1060
|
-
return
|
|
1079
|
+
return wrapZodFetch(
|
|
1061
1080
|
EnvironmentVariableResponseBody,
|
|
1062
1081
|
`${this.apiURL}/api/v1/projects/${projectRef}/envvars/${slug}/import`,
|
|
1063
1082
|
{
|
|
@@ -1074,7 +1093,7 @@ var CliApiClient = class {
|
|
|
1074
1093
|
if (!this.accessToken) {
|
|
1075
1094
|
throw new Error("initializeDeployment: No access token");
|
|
1076
1095
|
}
|
|
1077
|
-
return
|
|
1096
|
+
return wrapZodFetch(InitializeDeploymentResponseBody, `${this.apiURL}/api/v1/deployments`, {
|
|
1078
1097
|
method: "POST",
|
|
1079
1098
|
headers: {
|
|
1080
1099
|
Authorization: `Bearer ${this.accessToken}`,
|
|
@@ -1087,7 +1106,7 @@ var CliApiClient = class {
|
|
|
1087
1106
|
if (!this.accessToken) {
|
|
1088
1107
|
throw new Error("startDeploymentIndexing: No access token");
|
|
1089
1108
|
}
|
|
1090
|
-
return
|
|
1109
|
+
return wrapZodFetch(
|
|
1091
1110
|
StartDeploymentIndexingResponseBody,
|
|
1092
1111
|
`${this.apiURL}/api/v1/deployments/${deploymentId}/start-indexing`,
|
|
1093
1112
|
{
|
|
@@ -1104,7 +1123,7 @@ var CliApiClient = class {
|
|
|
1104
1123
|
if (!this.accessToken) {
|
|
1105
1124
|
throw new Error("getDeployment: No access token");
|
|
1106
1125
|
}
|
|
1107
|
-
return
|
|
1126
|
+
return wrapZodFetch(
|
|
1108
1127
|
GetDeploymentResponseBody,
|
|
1109
1128
|
`${this.apiURL}/api/v1/deployments/${deploymentId}`,
|
|
1110
1129
|
{
|
|
@@ -1116,45 +1135,38 @@ var CliApiClient = class {
|
|
|
1116
1135
|
);
|
|
1117
1136
|
}
|
|
1118
1137
|
};
|
|
1119
|
-
async function
|
|
1138
|
+
async function wrapZodFetch(schema, url, requestInit) {
|
|
1120
1139
|
try {
|
|
1121
|
-
const response = await
|
|
1122
|
-
|
|
1140
|
+
const response = await zodfetch(schema, url, requestInit, {
|
|
1141
|
+
retry: {
|
|
1142
|
+
minTimeoutInMs: 500,
|
|
1143
|
+
maxTimeoutInMs: 5e3,
|
|
1144
|
+
maxAttempts: 3,
|
|
1145
|
+
factor: 2,
|
|
1146
|
+
randomize: false
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
return {
|
|
1150
|
+
success: true,
|
|
1151
|
+
data: response
|
|
1152
|
+
};
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
if (error instanceof APIError) {
|
|
1123
1155
|
return {
|
|
1124
1156
|
success: false,
|
|
1125
|
-
error:
|
|
1157
|
+
error: error.message
|
|
1126
1158
|
};
|
|
1127
|
-
}
|
|
1128
|
-
if (response.status >= 400 && response.status < 500) {
|
|
1129
|
-
const body = await response.json();
|
|
1130
|
-
if (!body.error) {
|
|
1131
|
-
return { success: false, error: "Something went wrong" };
|
|
1132
|
-
}
|
|
1133
|
-
return { success: false, error: body.error };
|
|
1134
|
-
}
|
|
1135
|
-
if (response.status !== 200) {
|
|
1159
|
+
} else if (error instanceof Error) {
|
|
1136
1160
|
return {
|
|
1137
1161
|
success: false,
|
|
1138
|
-
error:
|
|
1162
|
+
error: error.message
|
|
1139
1163
|
};
|
|
1140
|
-
}
|
|
1141
|
-
const jsonBody = await response.json();
|
|
1142
|
-
const parsedResult = schema.safeParse(jsonBody);
|
|
1143
|
-
if (parsedResult.success) {
|
|
1144
|
-
return { success: true, data: parsedResult.data };
|
|
1145
|
-
}
|
|
1146
|
-
if ("error" in jsonBody) {
|
|
1164
|
+
} else {
|
|
1147
1165
|
return {
|
|
1148
1166
|
success: false,
|
|
1149
|
-
error:
|
|
1167
|
+
error: String(error)
|
|
1150
1168
|
};
|
|
1151
1169
|
}
|
|
1152
|
-
return { success: false, error: parsedResult.error.message };
|
|
1153
|
-
} catch (error) {
|
|
1154
|
-
return {
|
|
1155
|
-
success: false,
|
|
1156
|
-
error: error instanceof Error ? error.message : JSON.stringify(error)
|
|
1157
|
-
};
|
|
1158
1170
|
}
|
|
1159
1171
|
}
|
|
1160
1172
|
|
|
@@ -2599,7 +2611,7 @@ async function whoAmI(options, embedded = false) {
|
|
|
2599
2611
|
loadingSpinner.stop(
|
|
2600
2612
|
`You must login first. Use \`trigger.dev login --profile ${options?.profile ?? "default"}\` to login.`
|
|
2601
2613
|
);
|
|
2602
|
-
outro2(
|
|
2614
|
+
outro2(`Whoami failed: ${authentication.error}`);
|
|
2603
2615
|
}
|
|
2604
2616
|
}
|
|
2605
2617
|
return {
|
|
@@ -4003,7 +4015,11 @@ async function _deployCommand(dir, options) {
|
|
|
4003
4015
|
`Failed to connect to ${authorization.auth?.apiUrl}. Are you sure it's the correct URL?`
|
|
4004
4016
|
);
|
|
4005
4017
|
} else {
|
|
4006
|
-
throw new Error(
|
|
4018
|
+
throw new Error(
|
|
4019
|
+
`You must login first. Use the \`login\` CLI command.
|
|
4020
|
+
|
|
4021
|
+
${authorization.error}`
|
|
4022
|
+
);
|
|
4007
4023
|
}
|
|
4008
4024
|
}
|
|
4009
4025
|
span?.setAttributes({
|
|
@@ -4363,7 +4379,7 @@ async function failDeploy(shortCode, errorSummary, logs, deploymentSpinner, warn
|
|
|
4363
4379
|
outro5(`${chalkError("Error:")} ${errorSummary}.`);
|
|
4364
4380
|
}
|
|
4365
4381
|
}
|
|
4366
|
-
async function waitForDeploymentToFinish(deploymentId, client, timeoutInSeconds =
|
|
4382
|
+
async function waitForDeploymentToFinish(deploymentId, client, timeoutInSeconds = 180) {
|
|
4367
4383
|
return tracer.startActiveSpan("waitForDeploymentToFinish", async (span) => {
|
|
4368
4384
|
try {
|
|
4369
4385
|
const start = Date.now();
|
|
@@ -5274,6 +5290,31 @@ var TaskMetadataParseError = class extends Error {
|
|
|
5274
5290
|
this.name = "TaskMetadataParseError";
|
|
5275
5291
|
}
|
|
5276
5292
|
};
|
|
5293
|
+
var UnexpectedExitError = class extends Error {
|
|
5294
|
+
constructor(code) {
|
|
5295
|
+
super(`Unexpected exit with code ${code}`);
|
|
5296
|
+
this.code = code;
|
|
5297
|
+
this.name = "UnexpectedExitError";
|
|
5298
|
+
}
|
|
5299
|
+
};
|
|
5300
|
+
var CleanupProcessError = class extends Error {
|
|
5301
|
+
constructor() {
|
|
5302
|
+
super("Cancelled");
|
|
5303
|
+
this.name = "CleanupProcessError";
|
|
5304
|
+
}
|
|
5305
|
+
};
|
|
5306
|
+
var CancelledProcessError = class extends Error {
|
|
5307
|
+
constructor() {
|
|
5308
|
+
super("Cancelled");
|
|
5309
|
+
this.name = "CancelledProcessError";
|
|
5310
|
+
}
|
|
5311
|
+
};
|
|
5312
|
+
var SigKillTimeoutProcessError = class extends Error {
|
|
5313
|
+
constructor() {
|
|
5314
|
+
super("Process kill timeout");
|
|
5315
|
+
this.name = "SigKillTimeoutProcessError";
|
|
5316
|
+
}
|
|
5317
|
+
};
|
|
5277
5318
|
|
|
5278
5319
|
// src/workers/dev/backgroundWorker.ts
|
|
5279
5320
|
import {
|
|
@@ -5293,23 +5334,31 @@ import terminalLink3 from "terminal-link";
|
|
|
5293
5334
|
var BackgroundWorkerCoordinator = class {
|
|
5294
5335
|
constructor(baseURL) {
|
|
5295
5336
|
this.baseURL = baseURL;
|
|
5296
|
-
this.onTaskCompleted.attach(async ({ completion
|
|
5337
|
+
this.onTaskCompleted.attach(async ({ completion }) => {
|
|
5297
5338
|
if (!completion.ok && typeof completion.retry !== "undefined") {
|
|
5298
5339
|
return;
|
|
5299
5340
|
}
|
|
5300
|
-
await this.#notifyWorkersOfTaskCompletion(completion
|
|
5341
|
+
await this.#notifyWorkersOfTaskCompletion(completion);
|
|
5342
|
+
});
|
|
5343
|
+
this.onTaskFailedToRun.attach(async ({ completion }) => {
|
|
5344
|
+
await this.#notifyWorkersOfTaskCompletion(completion);
|
|
5301
5345
|
});
|
|
5302
5346
|
}
|
|
5303
5347
|
onTaskCompleted = new Evt();
|
|
5348
|
+
onTaskFailedToRun = new Evt();
|
|
5304
5349
|
onWorkerRegistered = new Evt();
|
|
5350
|
+
/**
|
|
5351
|
+
* @deprecated use onWorkerTaskRunHeartbeat instead
|
|
5352
|
+
*/
|
|
5305
5353
|
onWorkerTaskHeartbeat = new Evt();
|
|
5354
|
+
onWorkerTaskRunHeartbeat = new Evt();
|
|
5306
5355
|
onWorkerDeprecated = new Evt();
|
|
5307
5356
|
_backgroundWorkers = /* @__PURE__ */ new Map();
|
|
5308
5357
|
_records = /* @__PURE__ */ new Map();
|
|
5309
5358
|
_deprecatedWorkers = /* @__PURE__ */ new Set();
|
|
5310
|
-
async #notifyWorkersOfTaskCompletion(completion
|
|
5359
|
+
async #notifyWorkersOfTaskCompletion(completion) {
|
|
5311
5360
|
for (const worker of this._backgroundWorkers.values()) {
|
|
5312
|
-
await worker.taskRunCompletedNotification(completion
|
|
5361
|
+
await worker.taskRunCompletedNotification(completion);
|
|
5313
5362
|
}
|
|
5314
5363
|
}
|
|
5315
5364
|
get currentWorkers() {
|
|
@@ -5334,6 +5383,9 @@ var BackgroundWorkerCoordinator = class {
|
|
|
5334
5383
|
worker.onTaskHeartbeat.attach((id) => {
|
|
5335
5384
|
this.onWorkerTaskHeartbeat.post({ id, backgroundWorkerId: record.id, worker });
|
|
5336
5385
|
});
|
|
5386
|
+
worker.onTaskRunHeartbeat.attach((id) => {
|
|
5387
|
+
this.onWorkerTaskRunHeartbeat.post({ id, backgroundWorkerId: record.id, worker });
|
|
5388
|
+
});
|
|
5337
5389
|
}
|
|
5338
5390
|
close() {
|
|
5339
5391
|
for (const worker of this._backgroundWorkers.values()) {
|
|
@@ -5356,10 +5408,14 @@ var BackgroundWorkerCoordinator = class {
|
|
|
5356
5408
|
return;
|
|
5357
5409
|
}
|
|
5358
5410
|
await worker.cancelRun(message.taskRunId);
|
|
5411
|
+
break;
|
|
5412
|
+
}
|
|
5413
|
+
case "EXECUTE_RUN_LAZY_ATTEMPT": {
|
|
5414
|
+
await this.#executeTaskRunLazyAttempt(id, message.payload);
|
|
5359
5415
|
}
|
|
5360
5416
|
}
|
|
5361
5417
|
}
|
|
5362
|
-
async #
|
|
5418
|
+
async #executeTaskRunLazyAttempt(id, payload) {
|
|
5363
5419
|
const worker = this._backgroundWorkers.get(id);
|
|
5364
5420
|
if (!worker) {
|
|
5365
5421
|
logger.error(`Could not find worker ${id}`);
|
|
@@ -5370,96 +5426,80 @@ var BackgroundWorkerCoordinator = class {
|
|
|
5370
5426
|
logger.error(`Could not find worker record ${id}`);
|
|
5371
5427
|
return;
|
|
5372
5428
|
}
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
switch (error.type) {
|
|
5406
|
-
case "INTERNAL_ERROR": {
|
|
5407
|
-
return "";
|
|
5408
|
-
}
|
|
5409
|
-
case "STRING_ERROR": {
|
|
5410
|
-
return `
|
|
5411
|
-
|
|
5412
|
-
${chalkError("X Error:")} ${error.raw}
|
|
5413
|
-
`;
|
|
5414
|
-
}
|
|
5415
|
-
case "CUSTOM_ERROR": {
|
|
5416
|
-
return `
|
|
5417
|
-
|
|
5418
|
-
${chalkError("X Error:")} ${error.raw}
|
|
5419
|
-
`;
|
|
5420
|
-
}
|
|
5421
|
-
case "BUILT_IN_ERROR": {
|
|
5422
|
-
return `
|
|
5423
|
-
|
|
5424
|
-
${error.stackTrace.replace(/^Error: /, chalkError("X Error: "))}
|
|
5425
|
-
`;
|
|
5426
|
-
}
|
|
5429
|
+
try {
|
|
5430
|
+
const { completion, execution } = await worker.executeTaskRunLazyAttempt(
|
|
5431
|
+
payload,
|
|
5432
|
+
this.baseURL
|
|
5433
|
+
);
|
|
5434
|
+
this.onTaskCompleted.post({
|
|
5435
|
+
completion,
|
|
5436
|
+
execution,
|
|
5437
|
+
worker,
|
|
5438
|
+
backgroundWorkerId: id
|
|
5439
|
+
});
|
|
5440
|
+
} catch (error) {
|
|
5441
|
+
this.onTaskFailedToRun.post({
|
|
5442
|
+
backgroundWorkerId: id,
|
|
5443
|
+
worker,
|
|
5444
|
+
completion: {
|
|
5445
|
+
ok: false,
|
|
5446
|
+
id: payload.runId,
|
|
5447
|
+
retry: void 0,
|
|
5448
|
+
error: error instanceof Error ? {
|
|
5449
|
+
type: "BUILT_IN_ERROR",
|
|
5450
|
+
name: error.name,
|
|
5451
|
+
message: error.message,
|
|
5452
|
+
stackTrace: error.stack ?? ""
|
|
5453
|
+
} : {
|
|
5454
|
+
type: "BUILT_IN_ERROR",
|
|
5455
|
+
name: "UnknownError",
|
|
5456
|
+
message: String(error),
|
|
5457
|
+
stackTrace: ""
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
});
|
|
5427
5461
|
}
|
|
5428
5462
|
}
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5463
|
+
async #executeTaskRun(id, payload) {
|
|
5464
|
+
const worker = this._backgroundWorkers.get(id);
|
|
5465
|
+
if (!worker) {
|
|
5466
|
+
logger.error(`Could not find worker ${id}`);
|
|
5467
|
+
return;
|
|
5468
|
+
}
|
|
5469
|
+
const record = this._records.get(id);
|
|
5470
|
+
if (!record) {
|
|
5471
|
+
logger.error(`Could not find worker record ${id}`);
|
|
5472
|
+
return;
|
|
5473
|
+
}
|
|
5474
|
+
const completion = await worker.executeTaskRun(payload, this.baseURL);
|
|
5475
|
+
this.onTaskCompleted.post({
|
|
5476
|
+
completion,
|
|
5477
|
+
execution: payload.execution,
|
|
5478
|
+
worker,
|
|
5479
|
+
backgroundWorkerId: id
|
|
5480
|
+
});
|
|
5447
5481
|
}
|
|
5448
5482
|
};
|
|
5449
5483
|
var BackgroundWorker = class {
|
|
5450
|
-
constructor(path7, params) {
|
|
5484
|
+
constructor(path7, params, apiClient2) {
|
|
5451
5485
|
this.path = path7;
|
|
5452
5486
|
this.params = params;
|
|
5487
|
+
this.apiClient = apiClient2;
|
|
5453
5488
|
}
|
|
5454
5489
|
_initialized = false;
|
|
5455
5490
|
_handler = new ZodMessageHandler({
|
|
5456
5491
|
schema: childToWorkerMessages
|
|
5457
5492
|
});
|
|
5493
|
+
/**
|
|
5494
|
+
* @deprecated use onTaskRunHeartbeat instead
|
|
5495
|
+
*/
|
|
5458
5496
|
onTaskHeartbeat = new Evt();
|
|
5497
|
+
onTaskRunHeartbeat = new Evt();
|
|
5459
5498
|
_onClose = new Evt();
|
|
5460
5499
|
tasks = [];
|
|
5461
5500
|
metadata;
|
|
5462
5501
|
_taskRunProcesses = /* @__PURE__ */ new Map();
|
|
5502
|
+
_taskRunProcessesBeingKilled = /* @__PURE__ */ new Set();
|
|
5463
5503
|
_closed = false;
|
|
5464
5504
|
_fullEnv = {};
|
|
5465
5505
|
close() {
|
|
@@ -5468,6 +5508,7 @@ var BackgroundWorker = class {
|
|
|
5468
5508
|
}
|
|
5469
5509
|
this._closed = true;
|
|
5470
5510
|
this.onTaskHeartbeat.detach();
|
|
5511
|
+
this.onTaskRunHeartbeat.detach();
|
|
5471
5512
|
for (const taskRunProcess of this._taskRunProcesses.values()) {
|
|
5472
5513
|
taskRunProcess.cleanup(true);
|
|
5473
5514
|
}
|
|
@@ -5475,6 +5516,9 @@ var BackgroundWorker = class {
|
|
|
5475
5516
|
safeDeleteFileSync(this.path);
|
|
5476
5517
|
safeDeleteFileSync(`${this.path}.map`);
|
|
5477
5518
|
}
|
|
5519
|
+
get inProgressRuns() {
|
|
5520
|
+
return Array.from(this._taskRunProcesses.keys());
|
|
5521
|
+
}
|
|
5478
5522
|
async initialize() {
|
|
5479
5523
|
if (this._initialized) {
|
|
5480
5524
|
throw new Error("Worker already initialized");
|
|
@@ -5557,36 +5601,105 @@ var BackgroundWorker = class {
|
|
|
5557
5601
|
}
|
|
5558
5602
|
// We need to notify all the task run processes that a task run has completed,
|
|
5559
5603
|
// in case they are waiting for it through triggerAndWait
|
|
5560
|
-
async taskRunCompletedNotification(completion
|
|
5604
|
+
async taskRunCompletedNotification(completion) {
|
|
5561
5605
|
for (const taskRunProcess of this._taskRunProcesses.values()) {
|
|
5562
|
-
taskRunProcess.taskRunCompletedNotification(completion
|
|
5606
|
+
taskRunProcess.taskRunCompletedNotification(completion);
|
|
5563
5607
|
}
|
|
5564
5608
|
}
|
|
5565
|
-
|
|
5609
|
+
#prefixedMessage(payload, message = "") {
|
|
5610
|
+
return `[${payload.execution.run.id}.${payload.execution.attempt.number}] ${message}`;
|
|
5611
|
+
}
|
|
5612
|
+
async #getFreshTaskRunProcess(payload, messageId) {
|
|
5613
|
+
logger.debug(this.#prefixedMessage(payload, "getFreshTaskRunProcess()"));
|
|
5566
5614
|
if (!this.metadata) {
|
|
5567
5615
|
throw new Error("Worker not registered");
|
|
5568
5616
|
}
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
this.
|
|
5579
|
-
|
|
5580
|
-
|
|
5617
|
+
this._closed = false;
|
|
5618
|
+
logger.debug(this.#prefixedMessage(payload, "killing current task run process before attempt"));
|
|
5619
|
+
await this.#killCurrentTaskRunProcessBeforeAttempt(payload.execution.run.id);
|
|
5620
|
+
logger.debug(this.#prefixedMessage(payload, "creating new task run process"));
|
|
5621
|
+
const taskRunProcess = new TaskRunProcess(
|
|
5622
|
+
payload.execution.run.id,
|
|
5623
|
+
payload.execution.run.isTest,
|
|
5624
|
+
this.path,
|
|
5625
|
+
{
|
|
5626
|
+
...this._fullEnv,
|
|
5627
|
+
...payload.environment ?? {},
|
|
5628
|
+
...this.#readEnvVars()
|
|
5629
|
+
},
|
|
5630
|
+
this.metadata,
|
|
5631
|
+
this.params,
|
|
5632
|
+
messageId
|
|
5633
|
+
);
|
|
5634
|
+
taskRunProcess.onExit.attach(({ pid }) => {
|
|
5635
|
+
logger.debug(this.#prefixedMessage(payload, "onExit()"), { pid });
|
|
5636
|
+
const taskRunProcess2 = this._taskRunProcesses.get(payload.execution.run.id);
|
|
5637
|
+
if (taskRunProcess2?.pid === pid) {
|
|
5581
5638
|
this._taskRunProcesses.delete(payload.execution.run.id);
|
|
5582
|
-
}
|
|
5583
|
-
|
|
5584
|
-
this.
|
|
5585
|
-
}
|
|
5586
|
-
|
|
5587
|
-
|
|
5639
|
+
}
|
|
5640
|
+
if (pid) {
|
|
5641
|
+
this._taskRunProcessesBeingKilled.delete(pid);
|
|
5642
|
+
}
|
|
5643
|
+
});
|
|
5644
|
+
taskRunProcess.onIsBeingKilled.attach((pid) => {
|
|
5645
|
+
if (pid) {
|
|
5646
|
+
this._taskRunProcessesBeingKilled.add(pid);
|
|
5647
|
+
}
|
|
5648
|
+
});
|
|
5649
|
+
taskRunProcess.onTaskHeartbeat.attach((id) => {
|
|
5650
|
+
this.onTaskHeartbeat.post(id);
|
|
5651
|
+
});
|
|
5652
|
+
taskRunProcess.onTaskRunHeartbeat.attach((id) => {
|
|
5653
|
+
this.onTaskRunHeartbeat.post(id);
|
|
5654
|
+
});
|
|
5655
|
+
await taskRunProcess.initialize();
|
|
5656
|
+
this._taskRunProcesses.set(payload.execution.run.id, taskRunProcess);
|
|
5657
|
+
return taskRunProcess;
|
|
5658
|
+
}
|
|
5659
|
+
async #killCurrentTaskRunProcessBeforeAttempt(runId) {
|
|
5660
|
+
const taskRunProcess = this._taskRunProcesses.get(runId);
|
|
5661
|
+
if (!taskRunProcess) {
|
|
5662
|
+
logger.debug(`[${runId}] no current task process to kill`);
|
|
5663
|
+
return;
|
|
5664
|
+
}
|
|
5665
|
+
logger.debug(`[${runId}] killing current task process`, {
|
|
5666
|
+
pid: taskRunProcess.pid
|
|
5667
|
+
});
|
|
5668
|
+
if (taskRunProcess.isBeingKilled) {
|
|
5669
|
+
if (this._taskRunProcessesBeingKilled.size > 1) {
|
|
5670
|
+
await this.#tryGracefulExit(taskRunProcess);
|
|
5671
|
+
} else {
|
|
5672
|
+
}
|
|
5673
|
+
} else {
|
|
5674
|
+
if (this._taskRunProcessesBeingKilled.size > 0) {
|
|
5675
|
+
await this.#tryGracefulExit(taskRunProcess);
|
|
5676
|
+
} else {
|
|
5677
|
+
taskRunProcess.kill("SIGTERM", 5e3).catch(() => {
|
|
5678
|
+
});
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
}
|
|
5682
|
+
async #tryGracefulExit(taskRunProcess, kill = false, initialSignal = "SIGTERM") {
|
|
5683
|
+
try {
|
|
5684
|
+
const initialExit = taskRunProcess.onExit.waitFor(5e3);
|
|
5685
|
+
if (kill) {
|
|
5686
|
+
taskRunProcess.kill(initialSignal);
|
|
5687
|
+
}
|
|
5688
|
+
await initialExit;
|
|
5689
|
+
} catch (error) {
|
|
5690
|
+
logger.error("TaskRunProcess graceful kill timeout exceeded", error);
|
|
5691
|
+
this.#tryForcefulExit(taskRunProcess);
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
async #tryForcefulExit(taskRunProcess) {
|
|
5695
|
+
try {
|
|
5696
|
+
const forcedKill = taskRunProcess.onExit.waitFor(5e3);
|
|
5697
|
+
taskRunProcess.kill("SIGKILL");
|
|
5698
|
+
await forcedKill;
|
|
5699
|
+
} catch (error) {
|
|
5700
|
+
logger.error("TaskRunProcess forced kill timeout exceeded", error);
|
|
5701
|
+
throw new SigKillTimeoutProcessError();
|
|
5588
5702
|
}
|
|
5589
|
-
return this._taskRunProcesses.get(payload.execution.run.id);
|
|
5590
5703
|
}
|
|
5591
5704
|
async cancelRun(taskRunId) {
|
|
5592
5705
|
const taskRunProcess = this._taskRunProcesses.get(taskRunId);
|
|
@@ -5595,12 +5708,66 @@ var BackgroundWorker = class {
|
|
|
5595
5708
|
}
|
|
5596
5709
|
await taskRunProcess.cancel();
|
|
5597
5710
|
}
|
|
5711
|
+
async executeTaskRunLazyAttempt(payload, baseURL) {
|
|
5712
|
+
const attemptResponse = await this.apiClient.createTaskRunAttempt(payload.runId);
|
|
5713
|
+
if (!attemptResponse.success) {
|
|
5714
|
+
throw new Error(`Failed to create task run attempt: ${attemptResponse.error}`);
|
|
5715
|
+
}
|
|
5716
|
+
const execution = attemptResponse.data;
|
|
5717
|
+
const completion = await this.executeTaskRun(
|
|
5718
|
+
{ execution, traceContext: payload.traceContext, environment: payload.environment },
|
|
5719
|
+
baseURL,
|
|
5720
|
+
payload.messageId
|
|
5721
|
+
);
|
|
5722
|
+
return { execution, completion };
|
|
5723
|
+
}
|
|
5598
5724
|
// We need to fork the process before we can execute any tasks
|
|
5599
|
-
async executeTaskRun(payload) {
|
|
5725
|
+
async executeTaskRun(payload, baseURL, messageId) {
|
|
5726
|
+
if (this._closed) {
|
|
5727
|
+
throw new Error("Worker is closed");
|
|
5728
|
+
}
|
|
5729
|
+
if (!this.metadata) {
|
|
5730
|
+
throw new Error("Worker not registered");
|
|
5731
|
+
}
|
|
5732
|
+
const { execution } = payload;
|
|
5733
|
+
const logsUrl = `${baseURL}/runs/${execution.run.id}`;
|
|
5734
|
+
const pipe = chalkGrey("|");
|
|
5735
|
+
const bullet = chalkGrey("\u25CB");
|
|
5736
|
+
const link = chalkLink(terminalLink3("View logs", logsUrl));
|
|
5737
|
+
let timestampPrefix = chalkGrey(prettyPrintDate(payload.execution.attempt.startedAt));
|
|
5738
|
+
const workerPrefix = chalkWorker(this.metadata.version);
|
|
5739
|
+
const taskPrefix = chalkTask(execution.task.id);
|
|
5740
|
+
const runId = chalkRun(`${execution.run.id}.${execution.attempt.number}`);
|
|
5741
|
+
logger.log(
|
|
5742
|
+
`${bullet} ${timestampPrefix} ${chalkGrey(
|
|
5743
|
+
"->"
|
|
5744
|
+
)} ${link} ${pipe} ${workerPrefix} ${pipe} ${taskPrefix} ${pipe} ${runId}`
|
|
5745
|
+
);
|
|
5746
|
+
const now = performance.now();
|
|
5747
|
+
const completion = await this.#doExecuteTaskRun(payload, messageId);
|
|
5748
|
+
const elapsed = performance.now() - now;
|
|
5749
|
+
const retryingText = chalkGrey(
|
|
5750
|
+
!completion.ok && completion.skippedRetrying ? " (retrying skipped)" : !completion.ok && completion.retry !== void 0 ? ` (retrying in ${completion.retry.delay}ms)` : ""
|
|
5751
|
+
);
|
|
5752
|
+
const resultText = !completion.ok ? completion.error.type === "INTERNAL_ERROR" && (completion.error.code === TaskRunErrorCodes.TASK_EXECUTION_ABORTED || completion.error.code === TaskRunErrorCodes.TASK_RUN_CANCELLED) ? chalkWarning("Cancelled") : `${chalkError("Error")}${retryingText}` : chalkSuccess("Success");
|
|
5753
|
+
const errorText = !completion.ok ? formatErrorLog(completion.error) : "retry" in completion ? `retry in ${completion.retry}ms` : "";
|
|
5754
|
+
const elapsedText = chalkGrey(`(${formatDurationMilliseconds(elapsed, { style: "short" })})`);
|
|
5755
|
+
timestampPrefix = chalkGrey(prettyPrintDate());
|
|
5756
|
+
logger.log(
|
|
5757
|
+
`${bullet} ${timestampPrefix} ${chalkGrey(
|
|
5758
|
+
"->"
|
|
5759
|
+
)} ${link} ${pipe} ${workerPrefix} ${pipe} ${taskPrefix} ${pipe} ${runId} ${pipe} ${resultText} ${elapsedText}${errorText}`
|
|
5760
|
+
);
|
|
5761
|
+
return completion;
|
|
5762
|
+
}
|
|
5763
|
+
async #doExecuteTaskRun(payload, messageId) {
|
|
5600
5764
|
try {
|
|
5601
|
-
const taskRunProcess = await this.#
|
|
5765
|
+
const taskRunProcess = await this.#getFreshTaskRunProcess(payload, messageId);
|
|
5766
|
+
logger.debug(this.#prefixedMessage(payload, "executing task run"), {
|
|
5767
|
+
pid: taskRunProcess.pid
|
|
5768
|
+
});
|
|
5602
5769
|
const result = await taskRunProcess.executeTaskRun(payload);
|
|
5603
|
-
await taskRunProcess.cleanup(
|
|
5770
|
+
await taskRunProcess.cleanup(true);
|
|
5604
5771
|
if (result.ok) {
|
|
5605
5772
|
return result;
|
|
5606
5773
|
}
|
|
@@ -5677,12 +5844,14 @@ var BackgroundWorker = class {
|
|
|
5677
5844
|
}
|
|
5678
5845
|
};
|
|
5679
5846
|
var TaskRunProcess = class {
|
|
5680
|
-
constructor(
|
|
5681
|
-
this.
|
|
5847
|
+
constructor(runId, isTest, path7, env, metadata, worker, messageId) {
|
|
5848
|
+
this.runId = runId;
|
|
5849
|
+
this.isTest = isTest;
|
|
5682
5850
|
this.path = path7;
|
|
5683
5851
|
this.env = env;
|
|
5684
5852
|
this.metadata = metadata;
|
|
5685
5853
|
this.worker = worker;
|
|
5854
|
+
this.messageId = messageId;
|
|
5686
5855
|
this._sender = new ZodMessageSender({
|
|
5687
5856
|
schema: workerToChildMessages,
|
|
5688
5857
|
sender: async (message) => {
|
|
@@ -5697,20 +5866,26 @@ var TaskRunProcess = class {
|
|
|
5697
5866
|
});
|
|
5698
5867
|
_sender;
|
|
5699
5868
|
_child;
|
|
5869
|
+
_childPid;
|
|
5700
5870
|
_attemptPromises = /* @__PURE__ */ new Map();
|
|
5701
5871
|
_attemptStatuses = /* @__PURE__ */ new Map();
|
|
5702
5872
|
_currentExecution;
|
|
5703
5873
|
_isBeingKilled = false;
|
|
5704
5874
|
_isBeingCancelled = false;
|
|
5875
|
+
/**
|
|
5876
|
+
* @deprecated use onTaskRunHeartbeat instead
|
|
5877
|
+
*/
|
|
5705
5878
|
onTaskHeartbeat = new Evt();
|
|
5879
|
+
onTaskRunHeartbeat = new Evt();
|
|
5706
5880
|
onExit = new Evt();
|
|
5881
|
+
onIsBeingKilled = new Evt();
|
|
5707
5882
|
async cancel() {
|
|
5708
5883
|
this._isBeingCancelled = true;
|
|
5709
5884
|
await this.cleanup(true);
|
|
5710
5885
|
}
|
|
5711
5886
|
async initialize() {
|
|
5712
5887
|
const fullEnv = {
|
|
5713
|
-
...this.
|
|
5888
|
+
...this.isTest ? { TRIGGER_LOG_LEVEL: "debug" } : {},
|
|
5714
5889
|
...this.env,
|
|
5715
5890
|
OTEL_RESOURCE_ATTRIBUTES: JSON.stringify({
|
|
5716
5891
|
[SemanticInternalAttributes.PROJECT_DIR]: this.worker.projectConfig.projectDir
|
|
@@ -5719,7 +5894,7 @@ var TaskRunProcess = class {
|
|
|
5719
5894
|
...this.worker.debugOtel ? { OTEL_LOG_LEVEL: "debug" } : {}
|
|
5720
5895
|
};
|
|
5721
5896
|
const cwd = dirname2(this.path);
|
|
5722
|
-
logger.debug(`[${this.
|
|
5897
|
+
logger.debug(`[${this.runId}] initializing task run process`, {
|
|
5723
5898
|
env: fullEnv,
|
|
5724
5899
|
path: this.path,
|
|
5725
5900
|
cwd
|
|
@@ -5738,6 +5913,7 @@ var TaskRunProcess = class {
|
|
|
5738
5913
|
env: fullEnv,
|
|
5739
5914
|
execArgv: this.worker.debuggerOn ? ["--inspect-brk", "--trace-uncaught", "--no-warnings=ExperimentalWarning"] : ["--trace-uncaught", "--no-warnings=ExperimentalWarning"]
|
|
5740
5915
|
});
|
|
5916
|
+
this._childPid = this._child?.pid;
|
|
5741
5917
|
this._child.on("message", this.#handleMessage.bind(this));
|
|
5742
5918
|
this._child.on("exit", this.#handleExit.bind(this));
|
|
5743
5919
|
this._child.stdout?.on("data", this.#handleLog.bind(this));
|
|
@@ -5747,15 +5923,21 @@ var TaskRunProcess = class {
|
|
|
5747
5923
|
if (kill && this._isBeingKilled) {
|
|
5748
5924
|
return;
|
|
5749
5925
|
}
|
|
5750
|
-
|
|
5926
|
+
if (kill) {
|
|
5927
|
+
this._isBeingKilled = true;
|
|
5928
|
+
this.onIsBeingKilled.post(this._child?.pid);
|
|
5929
|
+
}
|
|
5930
|
+
logger.debug(`[${this.runId}] cleaning up task run process`, { kill, pid: this.pid });
|
|
5751
5931
|
await this._sender.send("CLEANUP", {
|
|
5752
5932
|
flush: true,
|
|
5753
5933
|
kill
|
|
5754
5934
|
});
|
|
5755
|
-
|
|
5935
|
+
if (!kill) {
|
|
5936
|
+
return;
|
|
5937
|
+
}
|
|
5756
5938
|
setTimeout(() => {
|
|
5757
5939
|
if (this._child && !this._child.killed) {
|
|
5758
|
-
logger.debug(`[${this.
|
|
5940
|
+
logger.debug(`[${this.runId}] killing task run process after timeout`, { pid: this.pid });
|
|
5759
5941
|
this._child.kill();
|
|
5760
5942
|
}
|
|
5761
5943
|
}, 5e3);
|
|
@@ -5780,20 +5962,19 @@ var TaskRunProcess = class {
|
|
|
5780
5962
|
this._currentExecution = void 0;
|
|
5781
5963
|
return result;
|
|
5782
5964
|
}
|
|
5783
|
-
taskRunCompletedNotification(completion
|
|
5965
|
+
taskRunCompletedNotification(completion) {
|
|
5784
5966
|
if (!completion.ok && typeof completion.retry !== "undefined") {
|
|
5785
5967
|
return;
|
|
5786
5968
|
}
|
|
5787
|
-
if (
|
|
5969
|
+
if (completion.id === this.runId) {
|
|
5788
5970
|
return;
|
|
5789
5971
|
}
|
|
5790
|
-
logger.debug(`[${this.
|
|
5791
|
-
completion
|
|
5792
|
-
execution
|
|
5972
|
+
logger.debug(`[${this.runId}] task run completed notification`, {
|
|
5973
|
+
completion
|
|
5793
5974
|
});
|
|
5794
5975
|
this._sender.send("TASK_RUN_COMPLETED_NOTIFICATION", {
|
|
5795
|
-
|
|
5796
|
-
|
|
5976
|
+
version: "v2",
|
|
5977
|
+
completion
|
|
5797
5978
|
});
|
|
5798
5979
|
}
|
|
5799
5980
|
async #handleMessage(msg) {
|
|
@@ -5815,12 +5996,16 @@ var TaskRunProcess = class {
|
|
|
5815
5996
|
break;
|
|
5816
5997
|
}
|
|
5817
5998
|
case "READY_TO_DISPOSE": {
|
|
5818
|
-
logger.debug(`[${this.
|
|
5999
|
+
logger.debug(`[${this.runId}] task run process is ready to dispose`);
|
|
5819
6000
|
this.#kill();
|
|
5820
6001
|
break;
|
|
5821
6002
|
}
|
|
5822
6003
|
case "TASK_HEARTBEAT": {
|
|
5823
|
-
this.
|
|
6004
|
+
if (this.messageId) {
|
|
6005
|
+
this.onTaskRunHeartbeat.post(this.messageId);
|
|
6006
|
+
} else {
|
|
6007
|
+
this.onTaskHeartbeat.post(message.payload.id);
|
|
6008
|
+
}
|
|
5824
6009
|
break;
|
|
5825
6010
|
}
|
|
5826
6011
|
case "TASKS_READY": {
|
|
@@ -5828,8 +6013,8 @@ var TaskRunProcess = class {
|
|
|
5828
6013
|
}
|
|
5829
6014
|
}
|
|
5830
6015
|
}
|
|
5831
|
-
async #handleExit(code) {
|
|
5832
|
-
logger.debug(`[${this.
|
|
6016
|
+
async #handleExit(code, signal) {
|
|
6017
|
+
logger.debug(`[${this.runId}] handle task run process exit`, { code, signal, pid: this.pid });
|
|
5833
6018
|
for (const [id, status] of this._attemptStatuses.entries()) {
|
|
5834
6019
|
if (status === "PENDING") {
|
|
5835
6020
|
this._attemptStatuses.set(id, "REJECTED");
|
|
@@ -5843,11 +6028,11 @@ var TaskRunProcess = class {
|
|
|
5843
6028
|
} else if (this._isBeingKilled) {
|
|
5844
6029
|
rejecter(new CleanupProcessError());
|
|
5845
6030
|
} else {
|
|
5846
|
-
rejecter(new UnexpectedExitError(code));
|
|
6031
|
+
rejecter(new UnexpectedExitError(code ?? -1));
|
|
5847
6032
|
}
|
|
5848
6033
|
}
|
|
5849
6034
|
}
|
|
5850
|
-
this.onExit.post(code);
|
|
6035
|
+
this.onExit.post({ code, signal, pid: this.pid });
|
|
5851
6036
|
}
|
|
5852
6037
|
#handleLog(data) {
|
|
5853
6038
|
if (!this._currentExecution) {
|
|
@@ -5877,12 +6062,57 @@ var TaskRunProcess = class {
|
|
|
5877
6062
|
);
|
|
5878
6063
|
}
|
|
5879
6064
|
#kill() {
|
|
6065
|
+
logger.debug(`[${this.runId}] #kill()`, { pid: this.pid });
|
|
5880
6066
|
if (this._child && !this._child.killed) {
|
|
5881
|
-
logger.debug(`[${this.execution.run.id}] killing task run process`);
|
|
5882
6067
|
this._child?.kill();
|
|
5883
6068
|
}
|
|
5884
6069
|
}
|
|
6070
|
+
async kill(signal, timeoutInMs) {
|
|
6071
|
+
logger.debug(`[${this.runId}] killing task run process`, {
|
|
6072
|
+
signal,
|
|
6073
|
+
timeoutInMs,
|
|
6074
|
+
pid: this.pid
|
|
6075
|
+
});
|
|
6076
|
+
this._isBeingKilled = true;
|
|
6077
|
+
const killTimeout = this.onExit.waitFor(timeoutInMs);
|
|
6078
|
+
this.onIsBeingKilled.post(this._child?.pid);
|
|
6079
|
+
this._child?.kill(signal);
|
|
6080
|
+
if (timeoutInMs) {
|
|
6081
|
+
await killTimeout;
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
6084
|
+
get isBeingKilled() {
|
|
6085
|
+
return this._isBeingKilled || this._child?.killed;
|
|
6086
|
+
}
|
|
6087
|
+
get pid() {
|
|
6088
|
+
return this._childPid;
|
|
6089
|
+
}
|
|
5885
6090
|
};
|
|
6091
|
+
function formatErrorLog(error) {
|
|
6092
|
+
switch (error.type) {
|
|
6093
|
+
case "INTERNAL_ERROR": {
|
|
6094
|
+
return "";
|
|
6095
|
+
}
|
|
6096
|
+
case "STRING_ERROR": {
|
|
6097
|
+
return `
|
|
6098
|
+
|
|
6099
|
+
${chalkError("X Error:")} ${error.raw}
|
|
6100
|
+
`;
|
|
6101
|
+
}
|
|
6102
|
+
case "CUSTOM_ERROR": {
|
|
6103
|
+
return `
|
|
6104
|
+
|
|
6105
|
+
${chalkError("X Error:")} ${error.raw}
|
|
6106
|
+
`;
|
|
6107
|
+
}
|
|
6108
|
+
case "BUILT_IN_ERROR": {
|
|
6109
|
+
return `
|
|
6110
|
+
|
|
6111
|
+
${error.stackTrace.replace(/^Error: /, chalkError("X Error: "))}
|
|
6112
|
+
`;
|
|
6113
|
+
}
|
|
6114
|
+
}
|
|
6115
|
+
}
|
|
5886
6116
|
|
|
5887
6117
|
// src/utilities/runtimeCheck.ts
|
|
5888
6118
|
function runtimeCheck(minimumMajor, minimumMinor) {
|
|
@@ -5945,7 +6175,11 @@ async function devCommand(dir, options) {
|
|
|
5945
6175
|
)} Connecting to the server failed. Please check your internet connection or contact eric@trigger.dev for help.`
|
|
5946
6176
|
);
|
|
5947
6177
|
} else {
|
|
5948
|
-
logger.log(
|
|
6178
|
+
logger.log(
|
|
6179
|
+
`${chalkError("X Error:")} You must login first. Use the \`login\` CLI command.
|
|
6180
|
+
|
|
6181
|
+
${authorization.error}`
|
|
6182
|
+
);
|
|
5949
6183
|
}
|
|
5950
6184
|
process.exitCode = 1;
|
|
5951
6185
|
return;
|
|
@@ -6084,6 +6318,17 @@ function useDev({
|
|
|
6084
6318
|
});
|
|
6085
6319
|
}
|
|
6086
6320
|
);
|
|
6321
|
+
backgroundWorkerCoordinator.onWorkerTaskRunHeartbeat.attach(
|
|
6322
|
+
async ({ worker, backgroundWorkerId, id }) => {
|
|
6323
|
+
await sender.send("BACKGROUND_WORKER_MESSAGE", {
|
|
6324
|
+
backgroundWorkerId,
|
|
6325
|
+
data: {
|
|
6326
|
+
type: "TASK_RUN_HEARTBEAT",
|
|
6327
|
+
id
|
|
6328
|
+
}
|
|
6329
|
+
});
|
|
6330
|
+
}
|
|
6331
|
+
);
|
|
6087
6332
|
backgroundWorkerCoordinator.onTaskCompleted.attach(
|
|
6088
6333
|
async ({ backgroundWorkerId, completion, execution }) => {
|
|
6089
6334
|
await sender.send("BACKGROUND_WORKER_MESSAGE", {
|
|
@@ -6096,6 +6341,17 @@ function useDev({
|
|
|
6096
6341
|
});
|
|
6097
6342
|
}
|
|
6098
6343
|
);
|
|
6344
|
+
backgroundWorkerCoordinator.onTaskFailedToRun.attach(
|
|
6345
|
+
async ({ backgroundWorkerId, completion }) => {
|
|
6346
|
+
await sender.send("BACKGROUND_WORKER_MESSAGE", {
|
|
6347
|
+
backgroundWorkerId,
|
|
6348
|
+
data: {
|
|
6349
|
+
type: "TASK_RUN_FAILED_TO_RUN",
|
|
6350
|
+
completion
|
|
6351
|
+
}
|
|
6352
|
+
});
|
|
6353
|
+
}
|
|
6354
|
+
);
|
|
6099
6355
|
backgroundWorkerCoordinator.onWorkerRegistered.attach(async ({ id, worker, record }) => {
|
|
6100
6356
|
await sender.send("READY_FOR_TASKS", {
|
|
6101
6357
|
backgroundWorkerId: id
|
|
@@ -6116,7 +6372,8 @@ function useDev({
|
|
|
6116
6372
|
SERVER_READY: async (payload) => {
|
|
6117
6373
|
for (const worker of backgroundWorkerCoordinator.currentWorkers) {
|
|
6118
6374
|
await sender.send("READY_FOR_TASKS", {
|
|
6119
|
-
backgroundWorkerId: worker.id
|
|
6375
|
+
backgroundWorkerId: worker.id,
|
|
6376
|
+
inProgressRuns: worker.worker.inProgressRuns
|
|
6120
6377
|
});
|
|
6121
6378
|
}
|
|
6122
6379
|
},
|
|
@@ -6252,19 +6509,23 @@ function useDev({
|
|
|
6252
6509
|
}
|
|
6253
6510
|
const environmentVariablesResponse = await environmentClient.getEnvironmentVariables(config.project);
|
|
6254
6511
|
const processEnv = await gatherProcessEnv();
|
|
6255
|
-
const backgroundWorker = new BackgroundWorker(
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6512
|
+
const backgroundWorker = new BackgroundWorker(
|
|
6513
|
+
fullPath,
|
|
6514
|
+
{
|
|
6515
|
+
projectConfig: config,
|
|
6516
|
+
dependencies: dependencies2,
|
|
6517
|
+
env: {
|
|
6518
|
+
...processEnv,
|
|
6519
|
+
TRIGGER_API_URL: apiUrl,
|
|
6520
|
+
TRIGGER_SECRET_KEY: apiKey,
|
|
6521
|
+
...environmentVariablesResponse.success ? environmentVariablesResponse.data.variables : {}
|
|
6522
|
+
},
|
|
6523
|
+
debuggerOn,
|
|
6524
|
+
debugOtel,
|
|
6525
|
+
resolveEnvVariables: createResolveEnvironmentVariablesFunction(configModule)
|
|
6263
6526
|
},
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
resolveEnvVariables: createResolveEnvironmentVariablesFunction(configModule)
|
|
6267
|
-
});
|
|
6527
|
+
environmentClient
|
|
6528
|
+
);
|
|
6268
6529
|
try {
|
|
6269
6530
|
await backgroundWorker.initialize();
|
|
6270
6531
|
latestWorkerContentHash = contentHash;
|
|
@@ -6307,7 +6568,8 @@ function useDev({
|
|
|
6307
6568
|
cliPackageVersion: version,
|
|
6308
6569
|
tasks: taskResources,
|
|
6309
6570
|
contentHash
|
|
6310
|
-
}
|
|
6571
|
+
},
|
|
6572
|
+
supportsLazyAttempts: true
|
|
6311
6573
|
};
|
|
6312
6574
|
const backgroundWorkerRecord = await environmentClient.createBackgroundWorker(
|
|
6313
6575
|
config.project,
|
|
@@ -6495,18 +6757,9 @@ ${task.filePath} -> ${task.exportName}`).join("")}`;
|
|
|
6495
6757
|
}
|
|
6496
6758
|
async function gatherProcessEnv() {
|
|
6497
6759
|
const env = {
|
|
6760
|
+
...process.env,
|
|
6498
6761
|
NODE_ENV: process.env.NODE_ENV ?? "development",
|
|
6499
|
-
|
|
6500
|
-
USER: process.env.USER,
|
|
6501
|
-
SHELL: process.env.SHELL,
|
|
6502
|
-
NVM_INC: process.env.NVM_INC,
|
|
6503
|
-
NVM_DIR: process.env.NVM_DIR,
|
|
6504
|
-
NVM_BIN: process.env.NVM_BIN,
|
|
6505
|
-
LANG: process.env.LANG,
|
|
6506
|
-
TERM: process.env.TERM,
|
|
6507
|
-
NODE_PATH: await amendNodePathWithPnpmNodeModules(process.env.NODE_PATH),
|
|
6508
|
-
HOME: process.env.HOME,
|
|
6509
|
-
BUN_INSTALL: process.env.BUN_INSTALL
|
|
6762
|
+
NODE_PATH: await amendNodePathWithPnpmNodeModules(process.env.NODE_PATH)
|
|
6510
6763
|
};
|
|
6511
6764
|
return Object.fromEntries(Object.entries(env).filter(([key, value]) => value !== void 0));
|
|
6512
6765
|
}
|