trigger.dev 0.0.0-v3-prerelease-20240427071154 → 0.0.0-v3-prerelease-20240501131706

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.
@@ -25,7 +25,7 @@ import {
25
25
  } from "@trigger.dev/core/v3/zodMessageHandler";
26
26
 
27
27
  // package.json
28
- var version = "0.0.0-v3-prerelease-20240427071154";
28
+ var version = "0.0.0-v3-prerelease-20240501131706";
29
29
 
30
30
  // src/workers/dev/worker-facade.ts
31
31
  __WORKER_SETUP__;
@@ -148,6 +148,7 @@ var ProdBackgroundWorker = class {
148
148
  onWaitForDuration = new Evt();
149
149
  onWaitForTask = new Evt();
150
150
  preCheckpointNotification = Evt.create();
151
+ checkpointCanceledNotification = Evt.create();
151
152
  onReadyForCheckpoint = Evt.create();
152
153
  onCancelCheckpoint = Evt.create();
153
154
  _onClose = new Evt();
@@ -296,6 +297,9 @@ var ProdBackgroundWorker = class {
296
297
  this.preCheckpointNotification.attach((message) => {
297
298
  taskRunProcess.preCheckpointNotification.post(message);
298
299
  });
300
+ this.checkpointCanceledNotification.attach((message) => {
301
+ taskRunProcess.checkpointCanceledNotification.post(message);
302
+ });
299
303
  await taskRunProcess.initialize();
300
304
  this._taskRunProcess = taskRunProcess;
301
305
  }
@@ -394,6 +398,7 @@ var TaskRunProcess = class {
394
398
  onWaitForDuration = new Evt();
395
399
  onWaitForTask = new Evt();
396
400
  preCheckpointNotification = Evt.create();
401
+ checkpointCanceledNotification = Evt.create();
397
402
  onReadyForCheckpoint = Evt.create();
398
403
  onCancelCheckpoint = Evt.create();
399
404
  async initialize() {
@@ -443,22 +448,49 @@ var TaskRunProcess = class {
443
448
  },
444
449
  TASKS_READY: async (message) => {
445
450
  },
451
+ WAIT_FOR_TASK: async (message) => {
452
+ this.onWaitForTask.post(message);
453
+ },
446
454
  WAIT_FOR_BATCH: async (message) => {
447
455
  this.onWaitForBatch.post(message);
448
456
  },
449
457
  WAIT_FOR_DURATION: async (message) => {
450
458
  this.onWaitForDuration.post(message);
451
- const { willCheckpointAndRestore } = await this.preCheckpointNotification.waitFor();
452
- return { willCheckpointAndRestore };
453
- },
454
- WAIT_FOR_TASK: async (message) => {
455
- this.onWaitForTask.post(message);
459
+ try {
460
+ const { willCheckpointAndRestore } = await this.preCheckpointNotification.waitFor(
461
+ 3e4
462
+ );
463
+ return {
464
+ willCheckpointAndRestore
465
+ };
466
+ } catch (error) {
467
+ console.error("Error while waiting for pre-checkpoint notification", error);
468
+ return {
469
+ willCheckpointAndRestore: false
470
+ };
471
+ }
456
472
  },
457
473
  READY_FOR_CHECKPOINT: async (message) => {
458
474
  this.onReadyForCheckpoint.post(message);
459
475
  },
460
476
  CANCEL_CHECKPOINT: async (message) => {
477
+ const version = "v2";
461
478
  this.onCancelCheckpoint.post(message);
479
+ try {
480
+ const { checkpointCanceled } = await this.checkpointCanceledNotification.waitFor(
481
+ 3e4
482
+ );
483
+ return {
484
+ version,
485
+ checkpointCanceled
486
+ };
487
+ } catch (error) {
488
+ console.error("Error while waiting for checkpoint cancellation", error);
489
+ return {
490
+ version,
491
+ checkpointCanceled: true
492
+ };
493
+ }
462
494
  }
463
495
  }
464
496
  });
@@ -593,18 +625,26 @@ var ProdWorker = class {
593
625
  this.#coordinatorSocket.socket.emit("TASK_HEARTBEAT", { version: "v1", attemptFriendlyId });
594
626
  });
595
627
  this.#backgroundWorker.onReadyForCheckpoint.attach(async (message) => {
628
+ await this.#backgroundWorker.flushTelemetry();
596
629
  this.#coordinatorSocket.socket.emit("READY_FOR_CHECKPOINT", { version: "v1" });
597
630
  });
598
631
  this.#backgroundWorker.onCancelCheckpoint.attach(async (message) => {
599
- logger2.log("onCancelCheckpoint() clearing paused state, don't wait for post start hook", {
600
- paused: this.paused,
601
- nextResumeAfter: this.nextResumeAfter,
602
- waitForPostStart: this.waitForPostStart
603
- });
604
- this.paused = false;
605
- this.nextResumeAfter = void 0;
606
- this.waitForPostStart = false;
607
- this.#coordinatorSocket.socket.emit("CANCEL_CHECKPOINT", { version: "v1" });
632
+ logger2.log("onCancelCheckpoint", { message });
633
+ const { checkpointCanceled } = await this.#coordinatorSocket.socket.emitWithAck(
634
+ "CANCEL_CHECKPOINT",
635
+ {
636
+ version: "v2",
637
+ reason: message.reason
638
+ }
639
+ );
640
+ if (checkpointCanceled) {
641
+ if (message.reason === "WAIT_FOR_DURATION") {
642
+ this.paused = false;
643
+ this.nextResumeAfter = void 0;
644
+ this.waitForPostStart = false;
645
+ }
646
+ }
647
+ this.#backgroundWorker.checkpointCanceledNotification.post({ checkpointCanceled });
608
648
  });
609
649
  this.#backgroundWorker.onWaitForDuration.attach(async (message) => {
610
650
  if (!this.attemptFriendlyId) {
@@ -720,13 +760,16 @@ var ProdWorker = class {
720
760
  this.#coordinatorSocket = this.#createCoordinatorSocket(coordinatorHost);
721
761
  }
722
762
  }
723
- #prepareForWait(reason, willCheckpointAndRestore) {
763
+ async #prepareForWait(reason, willCheckpointAndRestore) {
724
764
  logger2.log(`prepare for ${reason}`, { willCheckpointAndRestore });
725
765
  this.#backgroundWorker.preCheckpointNotification.post({ willCheckpointAndRestore });
726
766
  if (willCheckpointAndRestore) {
727
767
  this.paused = true;
728
768
  this.nextResumeAfter = reason;
729
769
  this.waitForPostStart = true;
770
+ if (reason === "WAIT_FOR_TASK" || reason === "WAIT_FOR_BATCH") {
771
+ await this.#backgroundWorker.flushTelemetry();
772
+ }
730
773
  }
731
774
  }
732
775
  async #prepareForRetry(willCheckpointAndRestore, shouldExit) {
@@ -748,6 +791,7 @@ var ProdWorker = class {
748
791
  #resumeAfterDuration() {
749
792
  this.paused = false;
750
793
  this.nextResumeAfter = void 0;
794
+ this.waitForPostStart = false;
751
795
  this.#backgroundWorker.waitCompletedNotification();
752
796
  }
753
797
  #returnValidatedExtraHeaders(headers) {
@@ -758,6 +802,7 @@ var ProdWorker = class {
758
802
  }
759
803
  return headers;
760
804
  }
805
+ // FIXME: If the the worker can't connect for a while, this runs MANY times - it should only run once
761
806
  #createCoordinatorSocket(host) {
762
807
  const extraHeaders = this.#returnValidatedExtraHeaders({
763
808
  "x-machine-name": MACHINE_NAME2,
@@ -822,6 +867,7 @@ var ProdWorker = class {
822
867
  }
823
868
  this.paused = false;
824
869
  this.nextResumeAfter = void 0;
870
+ this.waitForPostStart = false;
825
871
  for (let i = 0; i < message.completions.length; i++) {
826
872
  const completion = message.completions[i];
827
873
  const execution = message.executions[i];
@@ -893,6 +939,21 @@ var ProdWorker = class {
893
939
  logger3.log("skip connection handler, waiting for post start hook");
894
940
  return;
895
941
  }
942
+ if (this.paused) {
943
+ if (!this.nextResumeAfter) {
944
+ return;
945
+ }
946
+ if (!this.attemptFriendlyId) {
947
+ logger3.error("Missing friendly ID");
948
+ return;
949
+ }
950
+ socket.emit("READY_FOR_RESUME", {
951
+ version: "v1",
952
+ attemptFriendlyId: this.attemptFriendlyId,
953
+ type: this.nextResumeAfter
954
+ });
955
+ return;
956
+ }
896
957
  if (process.env.INDEX_TASKS === "true") {
897
958
  try {
898
959
  const taskResources = await this.#initializeWorker();
@@ -972,25 +1033,6 @@ var ProdWorker = class {
972
1033
  process.exit(111);
973
1034
  }
974
1035
  }
975
- if (this.paused) {
976
- if (!this.nextResumeAfter) {
977
- return;
978
- }
979
- if (!this.attemptFriendlyId) {
980
- logger3.error("Missing friendly ID");
981
- return;
982
- }
983
- if (this.nextResumeAfter === "WAIT_FOR_DURATION") {
984
- this.#resumeAfterDuration();
985
- return;
986
- }
987
- socket.emit("READY_FOR_RESUME", {
988
- version: "v1",
989
- attemptFriendlyId: this.attemptFriendlyId,
990
- type: this.nextResumeAfter
991
- });
992
- return;
993
- }
994
1036
  if (this.executing) {
995
1037
  return;
996
1038
  }
@@ -1027,7 +1069,8 @@ var ProdWorker = class {
1027
1069
  case "/status": {
1028
1070
  return reply.json({
1029
1071
  executing: this.executing,
1030
- pause: this.paused,
1072
+ paused: this.paused,
1073
+ completed: this.completed.size,
1031
1074
  nextResumeAfter: this.nextResumeAfter
1032
1075
  });
1033
1076
  }
@@ -25,7 +25,7 @@ import {
25
25
  import { ProdRuntimeManager } from "@trigger.dev/core/v3/prod";
26
26
 
27
27
  // package.json
28
- var version = "0.0.0-v3-prerelease-20240427071154";
28
+ var version = "0.0.0-v3-prerelease-20240501131706";
29
29
 
30
30
  // src/workers/prod/worker-facade.ts
31
31
  __WORKER_SETUP__;
@@ -127,7 +127,7 @@ var zodIpc = new ZodIpcConnection({
127
127
  prodRuntimeManager.resumeTask(completion, execution);
128
128
  },
129
129
  WAIT_COMPLETED_NOTIFICATION: async () => {
130
- prodRuntimeManager.resumeAfterRestore();
130
+ prodRuntimeManager.resumeAfterDuration();
131
131
  },
132
132
  CLEANUP: async ({ flush, kill }, sender) => {
133
133
  if (kill) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trigger.dev",
3
- "version": "0.0.0-v3-prerelease-20240427071154",
3
+ "version": "0.0.0-v3-prerelease-20240501131706",
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,8 +53,8 @@
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": "0.0.0-v3-prerelease-20240427071154",
57
- "@trigger.dev/tsconfig": "0.0.0"
56
+ "@trigger.dev/tsconfig": "0.0.0",
57
+ "@trigger.dev/core-apps": "0.0.0-v3-prerelease-20240501131706"
58
58
  },
59
59
  "dependencies": {
60
60
  "@anatine/esbuild-decorators": "^0.2.19",
@@ -72,7 +72,7 @@
72
72
  "@opentelemetry/sdk-trace-base": "^1.22.0",
73
73
  "@opentelemetry/sdk-trace-node": "^1.22.0",
74
74
  "@opentelemetry/semantic-conventions": "^1.22.0",
75
- "@trigger.dev/core": "0.0.0-v3-prerelease-20240427071154",
75
+ "@trigger.dev/core": "0.0.0-v3-prerelease-20240501131706",
76
76
  "@types/degit": "^2.8.3",
77
77
  "chalk": "^5.2.0",
78
78
  "chokidar": "^3.5.3",