trigger.dev 3.0.0-beta.13 → 3.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ import {
21
21
  } from "@trigger.dev/core/v3";
22
22
 
23
23
  // package.json
24
- var version = "3.0.0-beta.13";
24
+ var version = "3.0.0-beta.15";
25
25
 
26
26
  // src/workers/dev/worker-facade.ts
27
27
  __WORKER_SETUP__;
@@ -73,7 +73,7 @@ var handler = new ZodMessageHandler({
73
73
  execution,
74
74
  result: {
75
75
  ok: false,
76
- id: execution.attempt.id,
76
+ id: execution.run.id,
77
77
  error: {
78
78
  type: "INTERNAL_ERROR",
79
79
  code: TaskRunErrorCodes.TASK_ALREADY_RUNNING
@@ -90,7 +90,7 @@ var handler = new ZodMessageHandler({
90
90
  execution,
91
91
  result: {
92
92
  ok: false,
93
- id: execution.attempt.id,
93
+ id: execution.run.id,
94
94
  error: {
95
95
  type: "INTERNAL_ERROR",
96
96
  code: TaskRunErrorCodes.COULD_NOT_FIND_EXECUTOR
@@ -577,6 +577,7 @@ var logger2 = new SimpleLogger(`[${MACHINE_NAME2}][${SHORT_HASH}]`);
577
577
  var ProdWorker = class {
578
578
  constructor(port, host = "0.0.0.0") {
579
579
  this.host = host;
580
+ process.on("SIGTERM", this.#handleSignal.bind(this, "SIGTERM"));
580
581
  this.#coordinatorSocket = this.#createCoordinatorSocket(COORDINATOR_HOST);
581
582
  this.#backgroundWorker = new ProdBackgroundWorker("worker.js", {
582
583
  projectConfig: __PROJECT_CONFIG__,
@@ -669,6 +670,27 @@ var ProdWorker = class {
669
670
  #backgroundWorker;
670
671
  #httpServer;
671
672
  #coordinatorSocket;
673
+ async #handleSignal(signal) {
674
+ logger2.log("Received signal", { signal });
675
+ if (signal === "SIGTERM") {
676
+ if (this.executing) {
677
+ const terminationGracePeriodSeconds = 60 * 60;
678
+ logger2.log("Waiting for attempt to complete before exiting", {
679
+ terminationGracePeriodSeconds
680
+ });
681
+ await setTimeout2(terminationGracePeriodSeconds * 1e3 - 5e3);
682
+ logger2.log("Termination timeout reached, exiting gracefully.");
683
+ } else {
684
+ logger2.log("Not executing, exiting immediately.");
685
+ }
686
+ await this.#exitGracefully();
687
+ }
688
+ logger2.log("Unhandled signal", { signal });
689
+ }
690
+ async #exitGracefully() {
691
+ await this.#backgroundWorker.close();
692
+ process.exit(0);
693
+ }
672
694
  async #reconnect(isPostStart = false, reconnectImmediately = false) {
673
695
  if (isPostStart) {
674
696
  this.waitForPostStart = false;
@@ -713,8 +735,7 @@ var ProdWorker = class {
713
735
  if (willCheckpointAndRestore) {
714
736
  logger2.log("WARNING: Will checkpoint but also requested exit. This won't end well.");
715
737
  }
716
- await this.#backgroundWorker.close();
717
- process.exit(0);
738
+ await this.#exitGracefully();
718
739
  }
719
740
  this.executing = false;
720
741
  this.attemptFriendlyId = void 0;
@@ -1044,7 +1065,6 @@ var ProdWorker = class {
1044
1065
  break;
1045
1066
  }
1046
1067
  }
1047
- logger2.log("preStop", { url: req.url });
1048
1068
  return reply.text("preStop ok");
1049
1069
  }
1050
1070
  case "/postStart": {
@@ -23,7 +23,7 @@ import {
23
23
  } from "@trigger.dev/core/v3";
24
24
 
25
25
  // package.json
26
- var version = "3.0.0-beta.13";
26
+ var version = "3.0.0-beta.15";
27
27
 
28
28
  // src/workers/prod/worker-facade.ts
29
29
  __WORKER_SETUP__;
@@ -72,7 +72,7 @@ var zodIpc = new ZodIpcConnection({
72
72
  execution,
73
73
  result: {
74
74
  ok: false,
75
- id: execution.attempt.id,
75
+ id: execution.run.id,
76
76
  error: {
77
77
  type: "INTERNAL_ERROR",
78
78
  code: TaskRunErrorCodes.TASK_ALREADY_RUNNING
@@ -89,7 +89,7 @@ var zodIpc = new ZodIpcConnection({
89
89
  execution,
90
90
  result: {
91
91
  ok: false,
92
- id: execution.attempt.id,
92
+ id: execution.run.id,
93
93
  error: {
94
94
  type: "INTERNAL_ERROR",
95
95
  code: TaskRunErrorCodes.COULD_NOT_FIND_EXECUTOR
@@ -128,6 +128,20 @@ var zodIpc = new ZodIpcConnection({
128
128
  CLEANUP: async ({ flush, kill }, sender) => {
129
129
  if (kill) {
130
130
  await tracingSDK.flush();
131
+ if (_execution) {
132
+ await sender.send("TASK_RUN_COMPLETED", {
133
+ execution: _execution,
134
+ result: {
135
+ ok: false,
136
+ id: _execution.run.id,
137
+ error: {
138
+ type: "INTERNAL_ERROR",
139
+ code: TaskRunErrorCodes.GRACEFUL_EXIT_TIMEOUT,
140
+ message: "Worker process killed while attempt in progress."
141
+ }
142
+ }
143
+ });
144
+ }
131
145
  await sender.send("READY_TO_DISPOSE", void 0);
132
146
  } else {
133
147
  if (flush) {
@@ -137,6 +151,8 @@ var zodIpc = new ZodIpcConnection({
137
151
  }
138
152
  }
139
153
  });
154
+ process.on("SIGTERM", async () => {
155
+ });
140
156
  var prodRuntimeManager = new ProdRuntimeManager(zodIpc, {
141
157
  waitThresholdInMs: parseInt(process.env.TRIGGER_RUNTIME_WAIT_THRESHOLD_IN_MS ?? "30000", 10)
142
158
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trigger.dev",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.15",
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",
@@ -53,7 +53,7 @@
53
53
  "typescript": "^5.3.3",
54
54
  "vitest": "^0.34.4",
55
55
  "xdg-app-paths": "^8.3.0",
56
- "@trigger.dev/core-apps": "3.0.0-beta.13",
56
+ "@trigger.dev/core-apps": "3.0.0-beta.15",
57
57
  "@trigger.dev/tsconfig": "0.0.0"
58
58
  },
59
59
  "dependencies": {
@@ -71,7 +71,7 @@
71
71
  "@opentelemetry/sdk-trace-base": "^1.22.0",
72
72
  "@opentelemetry/sdk-trace-node": "^1.22.0",
73
73
  "@opentelemetry/semantic-conventions": "^1.22.0",
74
- "@trigger.dev/core": "^3.0.0-beta.13",
74
+ "@trigger.dev/core": "^3.0.0-beta.15",
75
75
  "@types/degit": "^2.8.3",
76
76
  "chalk": "^5.2.0",
77
77
  "chokidar": "^3.5.3",