Skip to content

Commit e4402d3

Browse files
authored
Worker: Work around lost run case (#1417)
* add workaround * versions * update test
1 parent 6421c17 commit e4402d3

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/ws-worker/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ws-worker
22

3+
## 1.25.1
4+
5+
### Patch Changes
6+
7+
- Add workaround for rare event duplication
8+
39
## 1.25.0
410

511
### Minor Changes

packages/ws-worker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/ws-worker",
3-
"version": "1.25.0",
3+
"version": "1.25.1",
44
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
55
"main": "dist/index.js",
66
"type": "module",

packages/ws-worker/src/events/step-complete.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ export default async function onStepComplete(
2222
const step_id = state.activeStep as string;
2323
const job_id = state.activeJob as string;
2424

25+
if (!step_id) {
26+
// Runs are lost in production now because sometimes the step-complete
27+
// event gets triggered twice. In this case, the second one does not
28+
// have an activeStep on the state object, so will send with
29+
// step_id null. And lightning will complain (rightly!) and refuse
30+
// to listen to subsequent events on the run (wrongly!)
31+
// This is hard to diagnose in the wild so as a temporary measure,
32+
// we're going to abort with a strong warning
33+
context.logger?.warn(
34+
`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.`
35+
);
36+
return;
37+
}
38+
2539
if (!state.dataclips) {
2640
state.dataclips = {};
2741
}

packages/ws-worker/test/api/execute.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ test('jobError should trigger step:complete with a reason and default state', as
206206
let stepCompleteEvent: any;
207207

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

210211
const channel = mockChannel({
211212
[STEP_COMPLETE]: (evt) => {

0 commit comments

Comments
 (0)