@openfn/ws-worker 1.5.1 → 1.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # ws-worker
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ca07db4: Fix an issue where a run with a missing start node caused the server to crash
8
+
9
+ ## 1.6.0
10
+
11
+ ### Minor Changes
12
+
13
+ - eaa3859: Include timestamps in key events
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [870a836]
18
+ - Updated dependencies [44f7f57]
19
+ - @openfn/engine-multi@1.2.2
20
+ - @openfn/lexicon@1.1.0
21
+ - @openfn/runtime@1.4.1
22
+
3
23
  ## 1.5.1
4
24
 
5
25
  ### Patch Changes
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ var name, version, description, main, type, scripts, bin, author, license, depen
29
29
  var init_package = __esm({
30
30
  "package.json"() {
31
31
  name = "@openfn/ws-worker";
32
- version = "1.5.1";
32
+ version = "1.6.1";
33
33
  description = "A Websocket Worker to connect Lightning to a Runtime Engine";
34
34
  main = "dist/index.js";
35
35
  type = "module";
@@ -142,7 +142,6 @@ var destroy = async (app, logger) => {
142
142
  await waitForRuns(app, logger);
143
143
  await app.engine.destroy();
144
144
  app.socket?.disconnect();
145
- logger.info("Server closed....");
146
145
  resolve();
147
146
  })
148
147
  ]);
@@ -468,10 +467,12 @@ var create_run_state_default = (plan, input) => {
468
467
  startNode = jobs.find(({ id }) => id === plan.options.start);
469
468
  }
470
469
  const initialRuns = [];
471
- if (!startNode.expression) {
472
- initialRuns.push(...Object.keys(startNode.next));
473
- } else {
474
- initialRuns.push(startNode.id);
470
+ if (startNode) {
471
+ if (!startNode.expression) {
472
+ initialRuns.push(...Object.keys(startNode.next));
473
+ } else {
474
+ initialRuns.push(startNode.id);
475
+ }
475
476
  }
476
477
  initialRuns.forEach((id) => {
477
478
  state.inputDataclips[id] = input;
@@ -508,6 +509,9 @@ var createThrottler = () => {
508
509
  };
509
510
  var throttle_default = createThrottler;
510
511
 
512
+ // src/util/timestamp.ts
513
+ var timeInMicroseconds = (time) => time && (BigInt(time) / BigInt(1e3)).toString();
514
+
511
515
  // src/events/run-start.ts
512
516
  import { timestamp } from "@openfn/logger";
513
517
 
@@ -549,7 +553,10 @@ async function onRunStart(context, event) {
549
553
  worker: package_default.version,
550
554
  ...event.versions
551
555
  };
552
- await sendEvent(channel, RUN_START, { versions });
556
+ await sendEvent(channel, RUN_START, {
557
+ versions,
558
+ timestamp: timeInMicroseconds(event.time)
559
+ });
553
560
  if ("payloadLimitMb" in options) {
554
561
  await onJobLog(versionLogContext, {
555
562
  time,
@@ -642,7 +649,8 @@ async function onStepComplete(context, event, error) {
642
649
  job_id,
643
650
  mem: event.mem,
644
651
  duration: event.duration,
645
- thread_id: event.threadId
652
+ thread_id: event.threadId,
653
+ timestamp: timeInMicroseconds(event.time)
646
654
  };
647
655
  try {
648
656
  if (!options || options.outputDataclips !== false) {
@@ -679,7 +687,8 @@ async function onStepStart(context, event) {
679
687
  await sendEvent(channel, STEP_START, {
680
688
  step_id: state.activeStep,
681
689
  job_id: state.activeJob,
682
- input_dataclip_id
690
+ input_dataclip_id,
691
+ timestamp: timeInMicroseconds(event.time)
683
692
  });
684
693
  }
685
694
 
@@ -701,7 +710,7 @@ ${reason.error_type}: ${reason.error_message || "unknown"}`;
701
710
  };
702
711
 
703
712
  // src/events/run-complete.ts
704
- async function onWorkflowComplete(context, _event) {
713
+ async function onWorkflowComplete(context, event) {
705
714
  const { state, channel, onFinish, logger } = context;
706
715
  const result = state.dataclips[state.lastDataclipId];
707
716
  const reason = calculateRunExitReason(state);
@@ -709,6 +718,7 @@ async function onWorkflowComplete(context, _event) {
709
718
  try {
710
719
  await sendEvent(channel, RUN_COMPLETE, {
711
720
  final_dataclip_id: state.lastDataclipId,
721
+ timestamp: timeInMicroseconds(event.time),
712
722
  ...reason
713
723
  });
714
724
  } catch (e) {
@@ -837,7 +847,6 @@ function onJobError(context, event) {
837
847
  }
838
848
  }
839
849
  function onJobLog({ channel, state, options }, event) {
840
- const timeInMicroseconds = BigInt(event.time) / BigInt(1e3);
841
850
  let message = event.message;
842
851
  try {
843
852
  if (typeof event.message === "string") {
@@ -857,7 +866,7 @@ function onJobLog({ channel, state, options }, event) {
857
866
  message,
858
867
  source: event.name,
859
868
  level: event.level,
860
- timestamp: timeInMicroseconds.toString()
869
+ timestamp: timeInMicroseconds(event.time)
861
870
  };
862
871
  if (state.activeStep) {
863
872
  log.step_id = state.activeStep;
@@ -1024,10 +1033,12 @@ function connect(app, logger, options = {}) {
1024
1033
  if (app.killWorkloop) {
1025
1034
  app.killWorkloop();
1026
1035
  delete app.killWorkloop;
1027
- logger.info("Connection to lightning lost.");
1028
- logger.info(
1029
- "Worker will automatically reconnect when lightning is back online."
1030
- );
1036
+ if (!app.destroyed) {
1037
+ logger.info("Connection to lightning lost");
1038
+ logger.info(
1039
+ "Worker will automatically reconnect when lightning is back online"
1040
+ );
1041
+ }
1031
1042
  }
1032
1043
  };
1033
1044
  const onError = (e) => {
package/dist/start.js CHANGED
@@ -37,7 +37,7 @@ var name, version, description, main, type, scripts, bin, author, license, depen
37
37
  var init_package = __esm({
38
38
  "package.json"() {
39
39
  name = "@openfn/ws-worker";
40
- version = "1.5.1";
40
+ version = "1.6.1";
41
41
  description = "A Websocket Worker to connect Lightning to a Runtime Engine";
42
42
  main = "dist/index.js";
43
43
  type = "module";
@@ -281,7 +281,6 @@ var destroy = async (app, logger2) => {
281
281
  await waitForRuns(app, logger2);
282
282
  await app.engine.destroy();
283
283
  app.socket?.disconnect();
284
- logger2.info("Server closed....");
285
284
  resolve5();
286
285
  })
287
286
  ]);
@@ -607,10 +606,12 @@ var create_run_state_default = (plan, input) => {
607
606
  startNode = jobs.find(({ id }) => id === plan.options.start);
608
607
  }
609
608
  const initialRuns = [];
610
- if (!startNode.expression) {
611
- initialRuns.push(...Object.keys(startNode.next));
612
- } else {
613
- initialRuns.push(startNode.id);
609
+ if (startNode) {
610
+ if (!startNode.expression) {
611
+ initialRuns.push(...Object.keys(startNode.next));
612
+ } else {
613
+ initialRuns.push(startNode.id);
614
+ }
614
615
  }
615
616
  initialRuns.forEach((id) => {
616
617
  state.inputDataclips[id] = input;
@@ -647,6 +648,9 @@ var createThrottler = () => {
647
648
  };
648
649
  var throttle_default = createThrottler;
649
650
 
651
+ // src/util/timestamp.ts
652
+ var timeInMicroseconds = (time) => time && (BigInt(time) / BigInt(1e3)).toString();
653
+
650
654
  // src/events/run-start.ts
651
655
  import { timestamp } from "@openfn/logger";
652
656
 
@@ -688,7 +692,10 @@ async function onRunStart(context, event) {
688
692
  worker: package_default.version,
689
693
  ...event.versions
690
694
  };
691
- await sendEvent(channel, RUN_START, { versions });
695
+ await sendEvent(channel, RUN_START, {
696
+ versions,
697
+ timestamp: timeInMicroseconds(event.time)
698
+ });
692
699
  if ("payloadLimitMb" in options) {
693
700
  await onJobLog(versionLogContext, {
694
701
  time,
@@ -781,7 +788,8 @@ async function onStepComplete(context, event, error) {
781
788
  job_id,
782
789
  mem: event.mem,
783
790
  duration: event.duration,
784
- thread_id: event.threadId
791
+ thread_id: event.threadId,
792
+ timestamp: timeInMicroseconds(event.time)
785
793
  };
786
794
  try {
787
795
  if (!options || options.outputDataclips !== false) {
@@ -818,7 +826,8 @@ async function onStepStart(context, event) {
818
826
  await sendEvent(channel, STEP_START, {
819
827
  step_id: state.activeStep,
820
828
  job_id: state.activeJob,
821
- input_dataclip_id
829
+ input_dataclip_id,
830
+ timestamp: timeInMicroseconds(event.time)
822
831
  });
823
832
  }
824
833
 
@@ -840,7 +849,7 @@ ${reason.error_type}: ${reason.error_message || "unknown"}`;
840
849
  };
841
850
 
842
851
  // src/events/run-complete.ts
843
- async function onWorkflowComplete(context, _event) {
852
+ async function onWorkflowComplete(context, event) {
844
853
  const { state, channel, onFinish, logger: logger2 } = context;
845
854
  const result = state.dataclips[state.lastDataclipId];
846
855
  const reason = calculateRunExitReason(state);
@@ -848,6 +857,7 @@ async function onWorkflowComplete(context, _event) {
848
857
  try {
849
858
  await sendEvent(channel, RUN_COMPLETE, {
850
859
  final_dataclip_id: state.lastDataclipId,
860
+ timestamp: timeInMicroseconds(event.time),
851
861
  ...reason
852
862
  });
853
863
  } catch (e) {
@@ -976,7 +986,6 @@ function onJobError(context, event) {
976
986
  }
977
987
  }
978
988
  function onJobLog({ channel, state, options }, event) {
979
- const timeInMicroseconds = BigInt(event.time) / BigInt(1e3);
980
989
  let message = event.message;
981
990
  try {
982
991
  if (typeof event.message === "string") {
@@ -996,7 +1005,7 @@ function onJobLog({ channel, state, options }, event) {
996
1005
  message,
997
1006
  source: event.name,
998
1007
  level: event.level,
999
- timestamp: timeInMicroseconds.toString()
1008
+ timestamp: timeInMicroseconds(event.time)
1000
1009
  };
1001
1010
  if (state.activeStep) {
1002
1011
  log.step_id = state.activeStep;
@@ -1163,10 +1172,12 @@ function connect(app, logger2, options = {}) {
1163
1172
  if (app.killWorkloop) {
1164
1173
  app.killWorkloop();
1165
1174
  delete app.killWorkloop;
1166
- logger2.info("Connection to lightning lost.");
1167
- logger2.info(
1168
- "Worker will automatically reconnect when lightning is back online."
1169
- );
1175
+ if (!app.destroyed) {
1176
+ logger2.info("Connection to lightning lost");
1177
+ logger2.info(
1178
+ "Worker will automatically reconnect when lightning is back online"
1179
+ );
1180
+ }
1170
1181
  }
1171
1182
  };
1172
1183
  const onError = (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/ws-worker",
3
- "version": "1.5.1",
3
+ "version": "1.6.1",
4
4
  "description": "A Websocket Worker to connect Lightning to a Runtime Engine",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -22,8 +22,8 @@
22
22
  "koa-logger": "^3.2.1",
23
23
  "phoenix": "1.7.10",
24
24
  "ws": "^8.14.1",
25
- "@openfn/engine-multi": "1.2.1",
26
- "@openfn/lexicon": "^1.0.2",
25
+ "@openfn/engine-multi": "1.2.2",
26
+ "@openfn/lexicon": "^1.1.0",
27
27
  "@openfn/logger": "1.0.1",
28
28
  "@openfn/runtime": "1.4.1"
29
29
  },
@@ -42,7 +42,7 @@
42
42
  "tsup": "^6.2.3",
43
43
  "typescript": "^4.6.4",
44
44
  "yargs": "^17.6.2",
45
- "@openfn/lightning-mock": "2.0.15"
45
+ "@openfn/lightning-mock": "2.0.16"
46
46
  },
47
47
  "files": [
48
48
  "dist",