@openfn/ws-worker 0.2.10 → 0.2.11
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.js +6 -3
- package/dist/start.js +29 -15
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# ws-worker
|
|
2
2
|
|
|
3
|
+
## 0.2.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 22339c6: Add MAX_RUN_MEMORY env var and option to limit the memory available to each run
|
|
8
|
+
- 04ac3cc: Include duration and threadid in run-complete
|
|
9
|
+
- 340b96e: Send memory usage to lightning on run:complete
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @openfn/engine-multi@0.2.2
|
|
12
|
+
- @openfn/runtime@0.2.1
|
|
13
|
+
|
|
3
14
|
## 0.2.10
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -424,12 +424,12 @@ function onJobComplete({ channel, state }, event, error) {
|
|
|
424
424
|
state.dataclips = {};
|
|
425
425
|
}
|
|
426
426
|
state.dataclips[dataclipId] = event.state;
|
|
427
|
+
delete state.activeRun;
|
|
428
|
+
delete state.activeJob;
|
|
427
429
|
state.lastDataclipId = dataclipId;
|
|
428
430
|
event.next?.forEach((nextJobId) => {
|
|
429
431
|
state.inputDataclips[nextJobId] = dataclipId;
|
|
430
432
|
});
|
|
431
|
-
delete state.activeRun;
|
|
432
|
-
delete state.activeJob;
|
|
433
433
|
const { reason, error_message, error_type } = calculateJobExitReason(
|
|
434
434
|
job_id,
|
|
435
435
|
event.state,
|
|
@@ -443,7 +443,10 @@ function onJobComplete({ channel, state }, event, error) {
|
|
|
443
443
|
output_dataclip: stringify_default(event.state),
|
|
444
444
|
reason,
|
|
445
445
|
error_message,
|
|
446
|
-
error_type
|
|
446
|
+
error_type,
|
|
447
|
+
mem: event.mem,
|
|
448
|
+
duration: event.duration,
|
|
449
|
+
thread_id: event.threadId
|
|
447
450
|
};
|
|
448
451
|
return sendEvent(channel, RUN_COMPLETE, evt);
|
|
449
452
|
}
|
package/dist/start.js
CHANGED
|
@@ -4865,6 +4865,7 @@ import createRTE from "@openfn/engine-multi";
|
|
|
4865
4865
|
|
|
4866
4866
|
// src/mock/runtime-engine.ts
|
|
4867
4867
|
import { EventEmitter } from "node:events";
|
|
4868
|
+
import crypto from "node:crypto";
|
|
4868
4869
|
import run from "@openfn/runtime";
|
|
4869
4870
|
|
|
4870
4871
|
// src/mock/resolvers.ts
|
|
@@ -4911,6 +4912,7 @@ async function createMock() {
|
|
|
4911
4912
|
}) => {
|
|
4912
4913
|
const { id, jobs } = xplan;
|
|
4913
4914
|
activeWorkflows[id] = true;
|
|
4915
|
+
const threadId = crypto.randomUUID();
|
|
4914
4916
|
for (const job of jobs) {
|
|
4915
4917
|
if (typeof job.configuration === "string") {
|
|
4916
4918
|
job.configuration = await options.resolvers?.credential?.(
|
|
@@ -4925,6 +4927,7 @@ async function createMock() {
|
|
|
4925
4927
|
log: (...args2) => {
|
|
4926
4928
|
dispatch("workflow-log", {
|
|
4927
4929
|
workflowId: id,
|
|
4930
|
+
threadId,
|
|
4928
4931
|
level: "info",
|
|
4929
4932
|
json: true,
|
|
4930
4933
|
message: args2,
|
|
@@ -4941,24 +4944,26 @@ async function createMock() {
|
|
|
4941
4944
|
notify: (name, payload) => {
|
|
4942
4945
|
dispatch(name, {
|
|
4943
4946
|
workflowId: id,
|
|
4947
|
+
threadId,
|
|
4944
4948
|
...payload
|
|
4945
4949
|
});
|
|
4946
4950
|
}
|
|
4947
4951
|
}
|
|
4948
4952
|
};
|
|
4949
4953
|
setTimeout(async () => {
|
|
4950
|
-
dispatch("workflow-start", { workflowId: id });
|
|
4954
|
+
dispatch("workflow-start", { workflowId: id, threadId });
|
|
4951
4955
|
try {
|
|
4952
4956
|
await run(xplan, void 0, opts);
|
|
4953
4957
|
} catch (e) {
|
|
4954
4958
|
dispatch("workflow-error", {
|
|
4959
|
+
threadId,
|
|
4955
4960
|
workflowId: id,
|
|
4956
4961
|
type: e.name,
|
|
4957
4962
|
message: e.message
|
|
4958
4963
|
});
|
|
4959
4964
|
}
|
|
4960
4965
|
delete activeWorkflows[id];
|
|
4961
|
-
dispatch("workflow-complete", { workflowId: id });
|
|
4966
|
+
dispatch("workflow-complete", { workflowId: id, threadId });
|
|
4962
4967
|
}, 1);
|
|
4963
4968
|
};
|
|
4964
4969
|
const getStatus = () => {
|
|
@@ -5146,10 +5151,10 @@ var startWorkloop = (app, logger2, minBackoff2, maxBackoff2, maxWorkers) => {
|
|
|
5146
5151
|
var workloop_default = startWorkloop;
|
|
5147
5152
|
|
|
5148
5153
|
// src/api/execute.ts
|
|
5149
|
-
import
|
|
5154
|
+
import crypto3 from "node:crypto";
|
|
5150
5155
|
|
|
5151
5156
|
// src/util/convert-attempt.ts
|
|
5152
|
-
import
|
|
5157
|
+
import crypto2 from "node:crypto";
|
|
5153
5158
|
var conditions = {
|
|
5154
5159
|
on_job_success: (upstreamId) => `Boolean(!state.errors?.["${upstreamId}"] ?? true)`,
|
|
5155
5160
|
on_job_failure: (upstreamId) => `Boolean(state.errors && state.errors["${upstreamId}"])`,
|
|
@@ -5196,7 +5201,7 @@ var convert_attempt_default = (attempt) => {
|
|
|
5196
5201
|
}
|
|
5197
5202
|
if (attempt.jobs?.length) {
|
|
5198
5203
|
attempt.jobs.forEach((job) => {
|
|
5199
|
-
const id = job.id ||
|
|
5204
|
+
const id = job.id || crypto2.randomUUID();
|
|
5200
5205
|
nodes[id] = {
|
|
5201
5206
|
id,
|
|
5202
5207
|
configuration: job.credential_id,
|
|
@@ -5379,7 +5384,7 @@ var sendEvent = (channel, event, payload) => new Promise((resolve5, reject) => {
|
|
|
5379
5384
|
channel.push(event, payload).receive("error", reject).receive("timeout", () => reject(new Error("timeout"))).receive("ok", resolve5);
|
|
5380
5385
|
});
|
|
5381
5386
|
function onJobStart({ channel, state }, event) {
|
|
5382
|
-
state.activeRun =
|
|
5387
|
+
state.activeRun = crypto3.randomUUID();
|
|
5383
5388
|
state.activeJob = event.jobId;
|
|
5384
5389
|
const input_dataclip_id = state.inputDataclips[event.jobId];
|
|
5385
5390
|
return sendEvent(channel, RUN_START, {
|
|
@@ -5397,19 +5402,19 @@ function onJobError(context, event) {
|
|
|
5397
5402
|
}
|
|
5398
5403
|
}
|
|
5399
5404
|
function onJobComplete({ channel, state }, event, error) {
|
|
5400
|
-
const dataclipId =
|
|
5405
|
+
const dataclipId = crypto3.randomUUID();
|
|
5401
5406
|
const run_id = state.activeRun;
|
|
5402
5407
|
const job_id = state.activeJob;
|
|
5403
5408
|
if (!state.dataclips) {
|
|
5404
5409
|
state.dataclips = {};
|
|
5405
5410
|
}
|
|
5406
5411
|
state.dataclips[dataclipId] = event.state;
|
|
5412
|
+
delete state.activeRun;
|
|
5413
|
+
delete state.activeJob;
|
|
5407
5414
|
state.lastDataclipId = dataclipId;
|
|
5408
5415
|
event.next?.forEach((nextJobId) => {
|
|
5409
5416
|
state.inputDataclips[nextJobId] = dataclipId;
|
|
5410
5417
|
});
|
|
5411
|
-
delete state.activeRun;
|
|
5412
|
-
delete state.activeJob;
|
|
5413
5418
|
const { reason, error_message, error_type } = calculateJobExitReason(
|
|
5414
5419
|
job_id,
|
|
5415
5420
|
event.state,
|
|
@@ -5423,7 +5428,10 @@ function onJobComplete({ channel, state }, event, error) {
|
|
|
5423
5428
|
output_dataclip: stringify_default(event.state),
|
|
5424
5429
|
reason,
|
|
5425
5430
|
error_message,
|
|
5426
|
-
error_type
|
|
5431
|
+
error_type,
|
|
5432
|
+
mem: event.mem,
|
|
5433
|
+
duration: event.duration,
|
|
5434
|
+
thread_id: event.threadId
|
|
5427
5435
|
};
|
|
5428
5436
|
return sendEvent(channel, RUN_COMPLETE, evt);
|
|
5429
5437
|
}
|
|
@@ -5707,7 +5715,7 @@ function createServer(engine, options = {}) {
|
|
|
5707
5715
|
var server_default = createServer;
|
|
5708
5716
|
|
|
5709
5717
|
// src/start.ts
|
|
5710
|
-
var { WORKER_REPO_DIR, WORKER_SECRET } = process.env;
|
|
5718
|
+
var { WORKER_REPO_DIR, WORKER_SECRET, MAX_RUN_MEMORY } = process.env;
|
|
5711
5719
|
var args = yargs_default(hideBin(process.argv)).command("server", "Start a ws-worker server").option("port", {
|
|
5712
5720
|
alias: "p",
|
|
5713
5721
|
description: "Port to run the server on",
|
|
@@ -5743,6 +5751,10 @@ var args = yargs_default(hideBin(process.argv)).command("server", "Start a ws-wo
|
|
|
5743
5751
|
description: "max concurrent workers",
|
|
5744
5752
|
default: 5,
|
|
5745
5753
|
type: "number"
|
|
5754
|
+
}).option("run-memory", {
|
|
5755
|
+
description: "Maximum memory allocated to a single run, in mb",
|
|
5756
|
+
type: "number",
|
|
5757
|
+
default: MAX_RUN_MEMORY ? parseInt(MAX_RUN_MEMORY) : 500
|
|
5746
5758
|
}).parse();
|
|
5747
5759
|
var logger = createLogger("SRV", { level: args.log });
|
|
5748
5760
|
if (args.lightning === "mock") {
|
|
@@ -5778,10 +5790,12 @@ if (args.mock) {
|
|
|
5778
5790
|
engineReady(engine);
|
|
5779
5791
|
});
|
|
5780
5792
|
} else {
|
|
5781
|
-
createRTE({ repoDir: args.repoDir }).then(
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5793
|
+
createRTE({ repoDir: args.repoDir, memoryLimitMb: args.runMemory }).then(
|
|
5794
|
+
(engine) => {
|
|
5795
|
+
logger.debug("engine created");
|
|
5796
|
+
engineReady(engine);
|
|
5797
|
+
}
|
|
5798
|
+
);
|
|
5785
5799
|
}
|
|
5786
5800
|
/**
|
|
5787
5801
|
* @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/ws-worker",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
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.2.
|
|
24
|
+
"@openfn/engine-multi": "0.2.2",
|
|
25
25
|
"@openfn/logger": "0.0.19",
|
|
26
|
-
"@openfn/runtime": "0.2.
|
|
26
|
+
"@openfn/runtime": "0.2.1"
|
|
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.1.
|
|
43
|
+
"@openfn/lightning-mock": "1.1.4"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"dist",
|