trigger.dev 3.0.0-beta.2 → 3.0.0-beta.20
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/Containerfile.prod +15 -4
- package/dist/index.js +1725 -606
- package/dist/index.js.map +1 -1
- package/dist/templates/trigger.config.ts.template +2 -1
- package/dist/workers/dev/worker-facade.js +51 -54
- package/dist/workers/dev/worker-setup.js +8 -3
- package/dist/workers/prod/entry-point.js +99 -43
- package/dist/workers/prod/worker-facade.js +62 -54
- package/dist/workers/prod/worker-setup.js +5 -3
- package/package.json +6 -13
|
@@ -2,24 +2,30 @@
|
|
|
2
2
|
import {
|
|
3
3
|
ProdChildToWorkerMessages,
|
|
4
4
|
ProdWorkerToChildMessages,
|
|
5
|
+
clock,
|
|
6
|
+
taskCatalog
|
|
7
|
+
} from "@trigger.dev/core/v3";
|
|
8
|
+
import {
|
|
5
9
|
TaskExecutor,
|
|
6
|
-
ZodIpcConnection,
|
|
7
10
|
DurableClock,
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
getEnvVar,
|
|
12
|
+
logLevels,
|
|
13
|
+
OtelTaskLogger,
|
|
14
|
+
ConsoleInterceptor
|
|
15
|
+
} from "@trigger.dev/core/v3/workers";
|
|
16
|
+
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
|
|
17
|
+
import { ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
|
|
10
18
|
import "source-map-support/register.js";
|
|
11
19
|
import {
|
|
12
|
-
ConsoleInterceptor,
|
|
13
|
-
OtelTaskLogger,
|
|
14
|
-
ProdRuntimeManager,
|
|
15
20
|
TaskRunErrorCodes,
|
|
16
21
|
TriggerTracer,
|
|
17
22
|
logger,
|
|
18
23
|
runtime
|
|
19
24
|
} from "@trigger.dev/core/v3";
|
|
25
|
+
import { ProdRuntimeManager } from "@trigger.dev/core/v3/prod";
|
|
20
26
|
|
|
21
27
|
// package.json
|
|
22
|
-
var version = "3.0.0-beta.
|
|
28
|
+
var version = "3.0.0-beta.20";
|
|
23
29
|
|
|
24
30
|
// src/workers/prod/worker-facade.ts
|
|
25
31
|
__WORKER_SETUP__;
|
|
@@ -29,60 +35,33 @@ var otelLogger = tracingSDK.getLogger("trigger-prod-worker", version);
|
|
|
29
35
|
var durableClock = new DurableClock();
|
|
30
36
|
clock.setGlobalClock(durableClock);
|
|
31
37
|
var tracer = new TriggerTracer({ tracer: otelTracer, logger: otelLogger });
|
|
32
|
-
var consoleInterceptor = new ConsoleInterceptor(otelLogger);
|
|
38
|
+
var consoleInterceptor = new ConsoleInterceptor(otelLogger, true);
|
|
39
|
+
var triggerLogLevel = getEnvVar("TRIGGER_LOG_LEVEL");
|
|
40
|
+
var configLogLevel = triggerLogLevel ? triggerLogLevel : importedConfig ? importedConfig.logLevel : __PROJECT_CONFIG__.logLevel;
|
|
33
41
|
var otelTaskLogger = new OtelTaskLogger({
|
|
34
42
|
logger: otelLogger,
|
|
35
43
|
tracer,
|
|
36
|
-
level: "
|
|
44
|
+
level: logLevels.includes(configLogLevel) ? configLogLevel : "log"
|
|
37
45
|
});
|
|
38
46
|
logger.setGlobalTaskLogger(otelTaskLogger);
|
|
39
47
|
var TaskFileImports = {};
|
|
40
48
|
var TaskFiles = {};
|
|
41
49
|
__TASKS__;
|
|
42
|
-
|
|
43
|
-
const result = [];
|
|
50
|
+
(() => {
|
|
44
51
|
for (const [importName, taskFile] of Object.entries(TaskFiles)) {
|
|
45
52
|
const fileImports = TaskFileImports[importName];
|
|
46
53
|
for (const [exportName, task] of Object.entries(fileImports ?? {})) {
|
|
47
|
-
if (task.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
retry: task.__trigger.retry,
|
|
55
|
-
machine: task.__trigger.machine,
|
|
56
|
-
fns: task.__trigger.fns
|
|
57
|
-
});
|
|
54
|
+
if (typeof task === "object" && task !== null && "id" in task && typeof task.id === "string") {
|
|
55
|
+
if (taskCatalog.taskExists(task.id)) {
|
|
56
|
+
taskCatalog.registerTaskFileMetadata(task.id, {
|
|
57
|
+
exportName,
|
|
58
|
+
filePath: taskFile.filePath
|
|
59
|
+
});
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
function getTaskMetadata() {
|
|
64
|
-
const result = getTasks();
|
|
65
|
-
return result.map((task) => {
|
|
66
|
-
const { fns, ...metadata } = task;
|
|
67
|
-
return metadata;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
var tasks = getTasks();
|
|
71
|
-
runtime.registerTasks(tasks);
|
|
72
|
-
var taskExecutors = /* @__PURE__ */ new Map();
|
|
73
|
-
for (const task of tasks) {
|
|
74
|
-
taskExecutors.set(
|
|
75
|
-
task.id,
|
|
76
|
-
new TaskExecutor(task, {
|
|
77
|
-
tracer,
|
|
78
|
-
tracingSDK,
|
|
79
|
-
consoleInterceptor,
|
|
80
|
-
projectConfig: __PROJECT_CONFIG__,
|
|
81
|
-
importedConfig,
|
|
82
|
-
handleErrorFn: handleError
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
}
|
|
64
|
+
})();
|
|
86
65
|
var _execution;
|
|
87
66
|
var _isRunning = false;
|
|
88
67
|
var zodIpc = new ZodIpcConnection({
|
|
@@ -97,7 +76,7 @@ var zodIpc = new ZodIpcConnection({
|
|
|
97
76
|
execution,
|
|
98
77
|
result: {
|
|
99
78
|
ok: false,
|
|
100
|
-
id: execution.
|
|
79
|
+
id: execution.run.id,
|
|
101
80
|
error: {
|
|
102
81
|
type: "INTERNAL_ERROR",
|
|
103
82
|
code: TaskRunErrorCodes.TASK_ALREADY_RUNNING
|
|
@@ -107,14 +86,14 @@ var zodIpc = new ZodIpcConnection({
|
|
|
107
86
|
return;
|
|
108
87
|
}
|
|
109
88
|
process.title = `trigger-prod-worker: ${execution.task.id} ${execution.run.id}`;
|
|
110
|
-
const
|
|
111
|
-
if (!
|
|
112
|
-
console.error(`Could not find
|
|
89
|
+
const task = taskCatalog.getTask(execution.task.id);
|
|
90
|
+
if (!task) {
|
|
91
|
+
console.error(`Could not find task ${execution.task.id}`);
|
|
113
92
|
await sender.send("TASK_RUN_COMPLETED", {
|
|
114
93
|
execution,
|
|
115
94
|
result: {
|
|
116
95
|
ok: false,
|
|
117
|
-
id: execution.
|
|
96
|
+
id: execution.run.id,
|
|
118
97
|
error: {
|
|
119
98
|
type: "INTERNAL_ERROR",
|
|
120
99
|
code: TaskRunErrorCodes.COULD_NOT_FIND_EXECUTOR
|
|
@@ -123,6 +102,14 @@ var zodIpc = new ZodIpcConnection({
|
|
|
123
102
|
});
|
|
124
103
|
return;
|
|
125
104
|
}
|
|
105
|
+
const executor = new TaskExecutor(task, {
|
|
106
|
+
tracer,
|
|
107
|
+
tracingSDK,
|
|
108
|
+
consoleInterceptor,
|
|
109
|
+
projectConfig: __PROJECT_CONFIG__,
|
|
110
|
+
importedConfig,
|
|
111
|
+
handleErrorFn: handleError
|
|
112
|
+
});
|
|
126
113
|
try {
|
|
127
114
|
_execution = execution;
|
|
128
115
|
_isRunning = true;
|
|
@@ -145,6 +132,20 @@ var zodIpc = new ZodIpcConnection({
|
|
|
145
132
|
CLEANUP: async ({ flush, kill }, sender) => {
|
|
146
133
|
if (kill) {
|
|
147
134
|
await tracingSDK.flush();
|
|
135
|
+
if (_execution) {
|
|
136
|
+
await sender.send("TASK_RUN_COMPLETED", {
|
|
137
|
+
execution: _execution,
|
|
138
|
+
result: {
|
|
139
|
+
ok: false,
|
|
140
|
+
id: _execution.run.id,
|
|
141
|
+
error: {
|
|
142
|
+
type: "INTERNAL_ERROR",
|
|
143
|
+
code: TaskRunErrorCodes.GRACEFUL_EXIT_TIMEOUT,
|
|
144
|
+
message: "Worker process killed while attempt in progress."
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
148
149
|
await sender.send("READY_TO_DISPOSE", void 0);
|
|
149
150
|
} else {
|
|
150
151
|
if (flush) {
|
|
@@ -154,12 +155,19 @@ var zodIpc = new ZodIpcConnection({
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
});
|
|
158
|
+
process.on("SIGTERM", async () => {
|
|
159
|
+
});
|
|
157
160
|
var prodRuntimeManager = new ProdRuntimeManager(zodIpc, {
|
|
158
161
|
waitThresholdInMs: parseInt(process.env.TRIGGER_RUNTIME_WAIT_THRESHOLD_IN_MS ?? "30000", 10)
|
|
159
162
|
});
|
|
160
163
|
runtime.setGlobalRuntimeManager(prodRuntimeManager);
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
var TASK_METADATA = taskCatalog.getAllTaskMetadata();
|
|
165
|
+
zodIpc.send("TASKS_READY", { tasks: TASK_METADATA }).catch((err) => {
|
|
166
|
+
if (err instanceof ZodSchemaParsedError) {
|
|
167
|
+
zodIpc.send("TASKS_FAILED_TO_PARSE", { zodIssues: err.error.issues, tasks: TASK_METADATA });
|
|
168
|
+
} else {
|
|
169
|
+
console.error("Failed to send TASKS_READY message", err);
|
|
170
|
+
}
|
|
163
171
|
});
|
|
164
172
|
process.title = "trigger-prod-worker";
|
|
165
173
|
async function asyncHeartbeat(initialDelayInSeconds = 30, intervalInSeconds = 5) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// src/workers/prod/worker-setup.ts
|
|
2
2
|
import { Resource } from "@opentelemetry/resources";
|
|
3
|
+
import { SemanticInternalAttributes, taskCatalog } from "@trigger.dev/core/v3";
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@trigger.dev/core/v3";
|
|
5
|
+
TracingSDK,
|
|
6
|
+
StandardTaskCatalog
|
|
7
|
+
} from "@trigger.dev/core/v3/workers";
|
|
7
8
|
__SETUP_IMPORTED_PROJECT_CONFIG__;
|
|
8
9
|
var tracingSDK = new TracingSDK({
|
|
9
10
|
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",
|
|
@@ -30,6 +31,7 @@ process.on("uncaughtException", (error, origin) => {
|
|
|
30
31
|
}
|
|
31
32
|
});
|
|
32
33
|
});
|
|
34
|
+
taskCatalog.setGlobalTaskCatalog(new StandardTaskCatalog());
|
|
33
35
|
export {
|
|
34
36
|
tracingSDK
|
|
35
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trigger.dev",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "A Command-Line Interface for Trigger.dev (v3) projects",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,11 +32,10 @@
|
|
|
32
32
|
"type": "module",
|
|
33
33
|
"exports": "./dist/index.js",
|
|
34
34
|
"bin": {
|
|
35
|
-
"
|
|
35
|
+
"triggerdev": "./dist/index.js"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/gradient-string": "^1.1.2",
|
|
39
|
-
"@types/jsonlines": "^0.1.5",
|
|
40
39
|
"@types/mock-fs": "^4.13.1",
|
|
41
40
|
"@types/node": "18",
|
|
42
41
|
"@types/object-hash": "^3.0.6",
|
|
@@ -44,8 +43,8 @@
|
|
|
44
43
|
"@types/semver": "^7.3.13",
|
|
45
44
|
"@types/ws": "^8.5.3",
|
|
46
45
|
"cpy-cli": "^5.0.0",
|
|
46
|
+
"nodemon": "^3.0.1",
|
|
47
47
|
"npm-run-all": "^4.1.5",
|
|
48
|
-
"npm-watch": "^0.11.0",
|
|
49
48
|
"open": "^10.0.3",
|
|
50
49
|
"p-retry": "^6.1.0",
|
|
51
50
|
"rimraf": "^3.0.2",
|
|
@@ -54,12 +53,9 @@
|
|
|
54
53
|
"typescript": "^5.3.3",
|
|
55
54
|
"vitest": "^0.34.4",
|
|
56
55
|
"xdg-app-paths": "^8.3.0",
|
|
57
|
-
"@trigger.dev/core-apps": "3.0.0-beta.
|
|
56
|
+
"@trigger.dev/core-apps": "3.0.0-beta.20",
|
|
58
57
|
"@trigger.dev/tsconfig": "0.0.0"
|
|
59
58
|
},
|
|
60
|
-
"watch": {
|
|
61
|
-
"build:prod-containerfile": "src/Containerfile.prod"
|
|
62
|
-
},
|
|
63
59
|
"dependencies": {
|
|
64
60
|
"@clack/prompts": "^0.7.0",
|
|
65
61
|
"@depot/cli": "0.0.1-cli.2.55.0",
|
|
@@ -75,7 +71,7 @@
|
|
|
75
71
|
"@opentelemetry/sdk-trace-base": "^1.22.0",
|
|
76
72
|
"@opentelemetry/sdk-trace-node": "^1.22.0",
|
|
77
73
|
"@opentelemetry/semantic-conventions": "^1.22.0",
|
|
78
|
-
"@trigger.dev/core": "
|
|
74
|
+
"@trigger.dev/core": "3.0.0-beta.20",
|
|
79
75
|
"@types/degit": "^2.8.3",
|
|
80
76
|
"chalk": "^5.2.0",
|
|
81
77
|
"chokidar": "^3.5.3",
|
|
@@ -92,12 +88,10 @@
|
|
|
92
88
|
"import-meta-resolve": "^4.0.0",
|
|
93
89
|
"ink": "^4.4.1",
|
|
94
90
|
"jsonc-parser": "^3.2.1",
|
|
95
|
-
"jsonlines": "^0.1.1",
|
|
96
91
|
"liquidjs": "^10.9.2",
|
|
97
92
|
"mock-fs": "^5.2.0",
|
|
98
93
|
"nanoid": "^4.0.2",
|
|
99
94
|
"node-fetch": "^3.3.0",
|
|
100
|
-
"npm-check-updates": "^16.12.2",
|
|
101
95
|
"object-hash": "^3.0.0",
|
|
102
96
|
"p-debounce": "^4.0.0",
|
|
103
97
|
"p-throttle": "^6.1.0",
|
|
@@ -109,7 +103,6 @@
|
|
|
109
103
|
"simple-git": "^3.19.0",
|
|
110
104
|
"socket.io-client": "^4.7.4",
|
|
111
105
|
"source-map-support": "^0.5.21",
|
|
112
|
-
"supports-color": "^9.4.0",
|
|
113
106
|
"terminal-link": "^3.0.0",
|
|
114
107
|
"tiny-invariant": "^1.2.0",
|
|
115
108
|
"tsconfig-paths": "^4.2.0",
|
|
@@ -131,7 +124,7 @@
|
|
|
131
124
|
"dev": "npm run clean && run-p dev:**",
|
|
132
125
|
"dev:main": "tsup --watch",
|
|
133
126
|
"dev:workers": "tsup --config tsup.workers.config.ts --watch",
|
|
134
|
-
"dev:
|
|
127
|
+
"dev:test": "nodemon -w src/Containerfile.prod -x npm run build:prod-containerfile",
|
|
135
128
|
"clean": "rimraf dist",
|
|
136
129
|
"start": "node dist/index.js",
|
|
137
130
|
"test": "vitest"
|