@openfn/ws-worker 1.22.3 → 1.23.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,17 @@
1
1
  # ws-worker
2
2
 
3
+ ## 1.23.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Even when sending final_dataclip_id, send finalState because it may be used by other consumers
8
+
9
+ ## 1.23.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 01a05ff: on send complete, only send final_state for multi-leaf output state. For single-leaf runs, reutrn final_dataclip_id
14
+
3
15
  ## 1.22.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -42,8 +42,8 @@ type RunState = {
42
42
  withheldDataclips: Record<string, true>;
43
43
  reasons: Record<string, ExitReason>;
44
44
 
45
- // final dataclip id
46
- lastDataclipId?: string;
45
+ // dataclip ids for leaf nodes (steps with no downstream)
46
+ leafDataclipIds: string[];
47
47
  };
48
48
 
49
49
  type ReceiveHook = {
package/dist/index.js CHANGED
@@ -379,7 +379,7 @@ var convert_lightning_plan_default = (run, options = {}) => {
379
379
  // src/util/create-run-state.ts
380
380
  var create_run_state_default = (plan, input) => {
381
381
  const state = {
382
- lastDataclipId: "",
382
+ leafDataclipIds: [],
383
383
  dataclips: {},
384
384
  inputDataclips: {},
385
385
  withheldDataclips: {},
@@ -730,7 +730,9 @@ async function onStepComplete(context, event, error) {
730
730
  state.dataclips[dataclipId] = event.state;
731
731
  delete state.activeStep;
732
732
  delete state.activeJob;
733
- state.lastDataclipId = dataclipId;
733
+ if (!event.next?.length) {
734
+ state.leafDataclipIds.push(dataclipId);
735
+ }
734
736
  event.next?.forEach((nextJobId) => {
735
737
  state.inputDataclips[nextJobId] = dataclipId;
736
738
  });
@@ -819,12 +821,17 @@ async function onWorkflowComplete(context, event) {
819
821
  const result = event.state;
820
822
  const reason = calculateRunExitReason(state);
821
823
  await log_final_reason_default(context, reason);
824
+ const isSingleLeaf = state.leafDataclipIds.length === 1 && !state.withheldDataclips[state.leafDataclipIds[0]];
825
+ const payload = {
826
+ timestamp: timeInMicroseconds(event.time),
827
+ final_state: result,
828
+ ...reason
829
+ };
830
+ if (isSingleLeaf) {
831
+ payload.final_dataclip_id = state.leafDataclipIds[0];
832
+ }
822
833
  try {
823
- await sendEvent(context, RUN_COMPLETE, {
824
- final_state: result,
825
- timestamp: timeInMicroseconds(event.time),
826
- ...reason
827
- });
834
+ await sendEvent(context, RUN_COMPLETE, payload);
828
835
  } catch (e) {
829
836
  logger.error(
830
837
  `${state.plan.id} failed to send ${RUN_COMPLETE} event. This run will be lost!`
package/dist/start.js CHANGED
@@ -527,7 +527,7 @@ var convert_lightning_plan_default = (run2, options = {}) => {
527
527
  // src/util/create-run-state.ts
528
528
  var create_run_state_default = (plan, input) => {
529
529
  const state = {
530
- lastDataclipId: "",
530
+ leafDataclipIds: [],
531
531
  dataclips: {},
532
532
  inputDataclips: {},
533
533
  withheldDataclips: {},
@@ -878,7 +878,9 @@ async function onStepComplete(context, event, error) {
878
878
  state.dataclips[dataclipId] = event.state;
879
879
  delete state.activeStep;
880
880
  delete state.activeJob;
881
- state.lastDataclipId = dataclipId;
881
+ if (!event.next?.length) {
882
+ state.leafDataclipIds.push(dataclipId);
883
+ }
882
884
  event.next?.forEach((nextJobId) => {
883
885
  state.inputDataclips[nextJobId] = dataclipId;
884
886
  });
@@ -967,12 +969,17 @@ async function onWorkflowComplete(context, event) {
967
969
  const result = event.state;
968
970
  const reason = calculateRunExitReason(state);
969
971
  await log_final_reason_default(context, reason);
972
+ const isSingleLeaf = state.leafDataclipIds.length === 1 && !state.withheldDataclips[state.leafDataclipIds[0]];
973
+ const payload = {
974
+ timestamp: timeInMicroseconds(event.time),
975
+ final_state: result,
976
+ ...reason
977
+ };
978
+ if (isSingleLeaf) {
979
+ payload.final_dataclip_id = state.leafDataclipIds[0];
980
+ }
970
981
  try {
971
- await sendEvent(context, RUN_COMPLETE, {
972
- final_state: result,
973
- timestamp: timeInMicroseconds(event.time),
974
- ...reason
975
- });
982
+ await sendEvent(context, RUN_COMPLETE, payload);
976
983
  } catch (e) {
977
984
  logger2.error(
978
985
  `${state.plan.id} failed to send ${RUN_COMPLETE} event. This run will be lost!`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/ws-worker",
3
- "version": "1.22.3",
3
+ "version": "1.23.1",
4
4
  "description": "A Websocket Worker to connect Lightning to a Runtime Engine",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "koa-logger": "^3.2.1",
24
24
  "phoenix": "1.7.10",
25
25
  "ws": "^8.19.0",
26
- "@openfn/engine-multi": "1.10.7",
27
26
  "@openfn/lexicon": "^1.4.2",
27
+ "@openfn/engine-multi": "1.10.7",
28
28
  "@openfn/logger": "1.1.2",
29
29
  "@openfn/runtime": "1.8.6"
30
30
  },