Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ws-worker

## 1.25.1

### Patch Changes

- Add workaround for rare event duplication

## 1.25.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.25.0",
"version": "1.25.1",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down
14 changes: 14 additions & 0 deletions packages/ws-worker/src/events/step-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export default async function onStepComplete(
const step_id = state.activeStep as string;
const job_id = state.activeJob as string;

if (!step_id) {
// Runs are lost in production now because sometimes the step-complete
// event gets triggered twice. In this case, the second one does not
// have an activeStep on the state object, so will send with
// step_id null. And lightning will complain (rightly!) and refuse
// to listen to subsequent events on the run (wrongly!)
// This is hard to diagnose in the wild so as a temporary measure,
// we're going to abort with a strong warning
context.logger?.warn(
`DUPLICATE_EVENT_ERROR: Run ${context.id} received two step:complete events for the same step. The second event has been suppressed to prevent a lost run.`
);
return;
}

if (!state.dataclips) {
state.dataclips = {};
}
Expand Down
1 change: 1 addition & 0 deletions packages/ws-worker/test/api/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ test('jobError should trigger step:complete with a reason and default state', as
let stepCompleteEvent: any;

const state = createRunState({ id: 'run-23' } as ExecutionPlan);
state.activeStep = 'a';

const channel = mockChannel({
[STEP_COMPLETE]: (evt) => {
Expand Down