@openfn/ws-worker 0.2.6 → 0.2.7
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 +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -14
- package/dist/start.js +21 -14
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# ws-worker
|
|
2
2
|
|
|
3
|
+
## 0.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d542aa9: worker: leave attempt channel when finished working
|
|
8
|
+
- Updated dependencies [793d523]
|
|
9
|
+
- Updated dependencies [857c42b]
|
|
10
|
+
- Updated dependencies [f17fb4a]
|
|
11
|
+
- @openfn/engine-multi@0.1.11
|
|
12
|
+
- @openfn/runtime@0.1.4
|
|
13
|
+
|
|
3
14
|
## 0.2.6
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -286,11 +286,11 @@ var eventMap = {
|
|
|
286
286
|
"workflow-log": ATTEMPT_LOG,
|
|
287
287
|
"workflow-complete": ATTEMPT_COMPLETE
|
|
288
288
|
};
|
|
289
|
-
function execute(channel, engine, logger, plan, options = {},
|
|
289
|
+
function execute(channel, engine, logger, plan, options = {}, onFinish = (_result) => {
|
|
290
290
|
}) {
|
|
291
291
|
logger.info("executing ", plan.id);
|
|
292
292
|
const state = create_attempt_state_default(plan, options);
|
|
293
|
-
const context = { channel, state, logger,
|
|
293
|
+
const context = { channel, state, logger, onFinish };
|
|
294
294
|
const addEvent = (eventName, handler) => {
|
|
295
295
|
const wrappedFn = async (event) => {
|
|
296
296
|
const lightningEvent = eventMap[eventName] ?? eventName;
|
|
@@ -337,7 +337,8 @@ function execute(channel, engine, logger, plan, options = {}, onComplete = (_res
|
|
|
337
337
|
onWorkflowError(context, {
|
|
338
338
|
workflowId: plan.id,
|
|
339
339
|
message: e.message,
|
|
340
|
-
type: e.type
|
|
340
|
+
type: e.type,
|
|
341
|
+
severity: e.severity
|
|
341
342
|
});
|
|
342
343
|
}
|
|
343
344
|
});
|
|
@@ -398,22 +399,27 @@ function onJobComplete({ channel, state }, event, error) {
|
|
|
398
399
|
function onWorkflowStart({ channel }, _event) {
|
|
399
400
|
return sendEvent(channel, ATTEMPT_START);
|
|
400
401
|
}
|
|
401
|
-
async function onWorkflowComplete({ state, channel,
|
|
402
|
+
async function onWorkflowComplete({ state, channel, onFinish }, _event) {
|
|
402
403
|
const result = state.dataclips[state.lastDataclipId];
|
|
403
404
|
const reason = calculateAttemptExitReason(state);
|
|
404
405
|
await sendEvent(channel, ATTEMPT_COMPLETE, {
|
|
405
406
|
final_dataclip_id: state.lastDataclipId,
|
|
406
407
|
...reason
|
|
407
408
|
});
|
|
408
|
-
|
|
409
|
+
onFinish({ reason, state: result });
|
|
409
410
|
}
|
|
410
|
-
async function onWorkflowError({ state, channel,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
411
|
+
async function onWorkflowError({ state, channel, logger, onFinish }, event) {
|
|
412
|
+
try {
|
|
413
|
+
const reason = calculateJobExitReason("", { data: {} }, event);
|
|
414
|
+
await sendEvent(channel, ATTEMPT_COMPLETE, {
|
|
415
|
+
final_dataclip_id: state.lastDataclipId,
|
|
416
|
+
...reason
|
|
417
|
+
});
|
|
418
|
+
onFinish({ reason });
|
|
419
|
+
} catch (e) {
|
|
420
|
+
logger.error("ERROR in workflow-error handler:", e.message);
|
|
421
|
+
logger.error(e);
|
|
422
|
+
}
|
|
417
423
|
}
|
|
418
424
|
function onJobLog({ channel, state }, event) {
|
|
419
425
|
const timeInMicroseconds = BigInt(event.time) / BigInt(1e3);
|
|
@@ -603,8 +609,9 @@ function createServer(engine, options = {}) {
|
|
|
603
609
|
plan,
|
|
604
610
|
options: options2
|
|
605
611
|
} = await attempt_default(app.socket, token, id, logger);
|
|
606
|
-
const
|
|
612
|
+
const onFinish = () => {
|
|
607
613
|
delete app.workflows[id];
|
|
614
|
+
attemptChannel.leave();
|
|
608
615
|
};
|
|
609
616
|
const context = execute(
|
|
610
617
|
attemptChannel,
|
|
@@ -612,7 +619,7 @@ function createServer(engine, options = {}) {
|
|
|
612
619
|
logger,
|
|
613
620
|
plan,
|
|
614
621
|
options2,
|
|
615
|
-
|
|
622
|
+
onFinish
|
|
616
623
|
);
|
|
617
624
|
app.workflows[id] = context;
|
|
618
625
|
} else {
|
package/dist/start.js
CHANGED
|
@@ -5274,11 +5274,11 @@ var eventMap = {
|
|
|
5274
5274
|
"workflow-log": ATTEMPT_LOG,
|
|
5275
5275
|
"workflow-complete": ATTEMPT_COMPLETE
|
|
5276
5276
|
};
|
|
5277
|
-
function execute(channel, engine, logger2, plan, options = {},
|
|
5277
|
+
function execute(channel, engine, logger2, plan, options = {}, onFinish = (_result) => {
|
|
5278
5278
|
}) {
|
|
5279
5279
|
logger2.info("executing ", plan.id);
|
|
5280
5280
|
const state = create_attempt_state_default(plan, options);
|
|
5281
|
-
const context = { channel, state, logger: logger2,
|
|
5281
|
+
const context = { channel, state, logger: logger2, onFinish };
|
|
5282
5282
|
const addEvent = (eventName, handler) => {
|
|
5283
5283
|
const wrappedFn = async (event) => {
|
|
5284
5284
|
const lightningEvent = eventMap[eventName] ?? eventName;
|
|
@@ -5325,7 +5325,8 @@ function execute(channel, engine, logger2, plan, options = {}, onComplete = (_re
|
|
|
5325
5325
|
onWorkflowError(context, {
|
|
5326
5326
|
workflowId: plan.id,
|
|
5327
5327
|
message: e.message,
|
|
5328
|
-
type: e.type
|
|
5328
|
+
type: e.type,
|
|
5329
|
+
severity: e.severity
|
|
5329
5330
|
});
|
|
5330
5331
|
}
|
|
5331
5332
|
});
|
|
@@ -5386,22 +5387,27 @@ function onJobComplete({ channel, state }, event, error) {
|
|
|
5386
5387
|
function onWorkflowStart({ channel }, _event) {
|
|
5387
5388
|
return sendEvent(channel, ATTEMPT_START);
|
|
5388
5389
|
}
|
|
5389
|
-
async function onWorkflowComplete({ state, channel,
|
|
5390
|
+
async function onWorkflowComplete({ state, channel, onFinish }, _event) {
|
|
5390
5391
|
const result = state.dataclips[state.lastDataclipId];
|
|
5391
5392
|
const reason = calculateAttemptExitReason(state);
|
|
5392
5393
|
await sendEvent(channel, ATTEMPT_COMPLETE, {
|
|
5393
5394
|
final_dataclip_id: state.lastDataclipId,
|
|
5394
5395
|
...reason
|
|
5395
5396
|
});
|
|
5396
|
-
|
|
5397
|
+
onFinish({ reason, state: result });
|
|
5397
5398
|
}
|
|
5398
|
-
async function onWorkflowError({ state, channel,
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5399
|
+
async function onWorkflowError({ state, channel, logger: logger2, onFinish }, event) {
|
|
5400
|
+
try {
|
|
5401
|
+
const reason = calculateJobExitReason("", { data: {} }, event);
|
|
5402
|
+
await sendEvent(channel, ATTEMPT_COMPLETE, {
|
|
5403
|
+
final_dataclip_id: state.lastDataclipId,
|
|
5404
|
+
...reason
|
|
5405
|
+
});
|
|
5406
|
+
onFinish({ reason });
|
|
5407
|
+
} catch (e) {
|
|
5408
|
+
logger2.error("ERROR in workflow-error handler:", e.message);
|
|
5409
|
+
logger2.error(e);
|
|
5410
|
+
}
|
|
5405
5411
|
}
|
|
5406
5412
|
function onJobLog({ channel, state }, event) {
|
|
5407
5413
|
const timeInMicroseconds = BigInt(event.time) / BigInt(1e3);
|
|
@@ -5591,8 +5597,9 @@ function createServer(engine, options = {}) {
|
|
|
5591
5597
|
plan,
|
|
5592
5598
|
options: options2
|
|
5593
5599
|
} = await attempt_default(app.socket, token, id, logger2);
|
|
5594
|
-
const
|
|
5600
|
+
const onFinish = () => {
|
|
5595
5601
|
delete app.workflows[id];
|
|
5602
|
+
attemptChannel.leave();
|
|
5596
5603
|
};
|
|
5597
5604
|
const context = execute(
|
|
5598
5605
|
attemptChannel,
|
|
@@ -5600,7 +5607,7 @@ function createServer(engine, options = {}) {
|
|
|
5600
5607
|
logger2,
|
|
5601
5608
|
plan,
|
|
5602
5609
|
options2,
|
|
5603
|
-
|
|
5610
|
+
onFinish
|
|
5604
5611
|
);
|
|
5605
5612
|
app.workflows[id] = context;
|
|
5606
5613
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/ws-worker",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"koa-logger": "^3.2.1",
|
|
22
22
|
"phoenix": "^1.7.7",
|
|
23
23
|
"ws": "^8.14.1",
|
|
24
|
-
"@openfn/engine-multi": "0.1.
|
|
25
|
-
"@openfn/
|
|
26
|
-
"@openfn/
|
|
24
|
+
"@openfn/engine-multi": "0.1.11",
|
|
25
|
+
"@openfn/runtime": "0.1.4",
|
|
26
|
+
"@openfn/logger": "0.0.19"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/koa": "^2.13.5",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"tsup": "^6.2.3",
|
|
41
41
|
"typescript": "^4.6.4",
|
|
42
42
|
"yargs": "^17.6.2",
|
|
43
|
-
"@openfn/lightning-mock": "1.0.
|
|
43
|
+
"@openfn/lightning-mock": "1.0.12"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|