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