@openfn/ws-worker 1.6.4 → 1.6.6
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 +15 -0
- package/dist/index.js +42 -30
- package/dist/start.js +46 -32
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# ws-worker
|
|
2
2
|
|
|
3
|
+
## 1.6.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Log claim event duration
|
|
8
|
+
|
|
9
|
+
## 1.6.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5db5862: Dont log compiled job code
|
|
14
|
+
- f581c6b: log duration of runs and server capacity
|
|
15
|
+
- 3e6eba2: Trap errors coming out of the websocket
|
|
16
|
+
- @openfn/engine-multi@1.2.5
|
|
17
|
+
|
|
3
18
|
## 1.6.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var name, version, description, main, type, scripts, bin, author, license, depen
|
|
|
29
29
|
var init_package = __esm({
|
|
30
30
|
"package.json"() {
|
|
31
31
|
name = "@openfn/ws-worker";
|
|
32
|
-
version = "1.6.
|
|
32
|
+
version = "1.6.6";
|
|
33
33
|
description = "A Websocket Worker to connect Lightning to a Runtime Engine";
|
|
34
34
|
main = "dist/index.js";
|
|
35
35
|
type = "module";
|
|
@@ -232,18 +232,21 @@ var claim = (app, logger = mockLogger, options = {}) => {
|
|
|
232
232
|
const { maxWorkers = 5 } = options;
|
|
233
233
|
const activeWorkers = Object.keys(app.workflows).length;
|
|
234
234
|
if (activeWorkers >= maxWorkers) {
|
|
235
|
-
logger.debug(
|
|
235
|
+
logger.debug(
|
|
236
|
+
`skipping claim attempt: server at capacity (${activeWorkers}/${maxWorkers})`
|
|
237
|
+
);
|
|
236
238
|
return reject(new Error("Server at capacity"));
|
|
237
239
|
}
|
|
238
240
|
if (!app.queueChannel) {
|
|
239
241
|
logger.debug("skipping claim attempt: websocket unavailable");
|
|
240
242
|
return reject(new Error("No websocket available"));
|
|
241
243
|
}
|
|
242
|
-
logger.debug(
|
|
244
|
+
logger.debug(`requesting run (capacity ${activeWorkers}/${maxWorkers})`);
|
|
245
|
+
const start = Date.now();
|
|
243
246
|
app.queueChannel.push(CLAIM, { demand: 1 }).receive("ok", ({ runs }) => {
|
|
247
|
+
const duration = Date.now() - start;
|
|
244
248
|
logger.debug(
|
|
245
|
-
`claimed ${runs.length} runs:
|
|
246
|
-
runs.map((r) => r.id).join(",")
|
|
249
|
+
`claimed ${runs.length} runs in ${duration}ms (${runs.length ? runs.map((r) => r.id).join(",") : "-"})`
|
|
247
250
|
);
|
|
248
251
|
if (!runs?.length) {
|
|
249
252
|
return reject(new Error("No runs returned"));
|
|
@@ -1088,32 +1091,41 @@ function createServer(engine, options = {}) {
|
|
|
1088
1091
|
app.options = options;
|
|
1089
1092
|
app.execute = async ({ id, token }) => {
|
|
1090
1093
|
if (app.socket) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1094
|
+
try {
|
|
1095
|
+
const start = Date.now();
|
|
1096
|
+
app.workflows[id] = true;
|
|
1097
|
+
const {
|
|
1098
|
+
channel: runChannel,
|
|
1099
|
+
plan,
|
|
1100
|
+
options: options2 = {},
|
|
1101
|
+
input
|
|
1102
|
+
} = await run_default(app.socket, token, id, logger);
|
|
1103
|
+
if (!("payloadLimitMb" in options2)) {
|
|
1104
|
+
options2.payloadLimitMb = app.options.payloadLimitMb;
|
|
1105
|
+
}
|
|
1106
|
+
const onFinish = () => {
|
|
1107
|
+
const duration = (Date.now() - start) / 1e3;
|
|
1108
|
+
logger.debug(
|
|
1109
|
+
`workflow ${id} complete in ${duration}s: releasing worker`
|
|
1110
|
+
);
|
|
1111
|
+
delete app.workflows[id];
|
|
1112
|
+
runChannel.leave();
|
|
1113
|
+
app.events.emit(INTERNAL_RUN_COMPLETE);
|
|
1114
|
+
};
|
|
1115
|
+
const context = execute(
|
|
1116
|
+
runChannel,
|
|
1117
|
+
engine,
|
|
1118
|
+
logger,
|
|
1119
|
+
plan,
|
|
1120
|
+
input,
|
|
1121
|
+
options2,
|
|
1122
|
+
onFinish
|
|
1123
|
+
);
|
|
1124
|
+
app.workflows[id] = context;
|
|
1125
|
+
} catch (e) {
|
|
1126
|
+
logger.error(`Unexpected error executing ${id}`);
|
|
1127
|
+
logger.error(e);
|
|
1100
1128
|
}
|
|
1101
|
-
const onFinish = () => {
|
|
1102
|
-
logger.debug(`workflow ${id} complete: releasing worker`);
|
|
1103
|
-
delete app.workflows[id];
|
|
1104
|
-
runChannel.leave();
|
|
1105
|
-
app.events.emit(INTERNAL_RUN_COMPLETE);
|
|
1106
|
-
};
|
|
1107
|
-
const context = execute(
|
|
1108
|
-
runChannel,
|
|
1109
|
-
engine,
|
|
1110
|
-
logger,
|
|
1111
|
-
plan,
|
|
1112
|
-
input,
|
|
1113
|
-
options2,
|
|
1114
|
-
onFinish
|
|
1115
|
-
);
|
|
1116
|
-
app.workflows[id] = context;
|
|
1117
1129
|
} else {
|
|
1118
1130
|
logger.error("No lightning socket established");
|
|
1119
1131
|
}
|
package/dist/start.js
CHANGED
|
@@ -37,7 +37,7 @@ var name, version, description, main, type, scripts, bin, author, license, depen
|
|
|
37
37
|
var init_package = __esm({
|
|
38
38
|
"package.json"() {
|
|
39
39
|
name = "@openfn/ws-worker";
|
|
40
|
-
version = "1.6.
|
|
40
|
+
version = "1.6.6";
|
|
41
41
|
description = "A Websocket Worker to connect Lightning to a Runtime Engine";
|
|
42
42
|
main = "dist/index.js";
|
|
43
43
|
type = "module";
|
|
@@ -371,18 +371,21 @@ var claim = (app, logger2 = mockLogger, options = {}) => {
|
|
|
371
371
|
const { maxWorkers = 5 } = options;
|
|
372
372
|
const activeWorkers = Object.keys(app.workflows).length;
|
|
373
373
|
if (activeWorkers >= maxWorkers) {
|
|
374
|
-
logger2.debug(
|
|
374
|
+
logger2.debug(
|
|
375
|
+
`skipping claim attempt: server at capacity (${activeWorkers}/${maxWorkers})`
|
|
376
|
+
);
|
|
375
377
|
return reject(new Error("Server at capacity"));
|
|
376
378
|
}
|
|
377
379
|
if (!app.queueChannel) {
|
|
378
380
|
logger2.debug("skipping claim attempt: websocket unavailable");
|
|
379
381
|
return reject(new Error("No websocket available"));
|
|
380
382
|
}
|
|
381
|
-
logger2.debug(
|
|
383
|
+
logger2.debug(`requesting run (capacity ${activeWorkers}/${maxWorkers})`);
|
|
384
|
+
const start = Date.now();
|
|
382
385
|
app.queueChannel.push(CLAIM, { demand: 1 }).receive("ok", ({ runs }) => {
|
|
386
|
+
const duration = Date.now() - start;
|
|
383
387
|
logger2.debug(
|
|
384
|
-
`claimed ${runs.length} runs:
|
|
385
|
-
runs.map((r) => r.id).join(",")
|
|
388
|
+
`claimed ${runs.length} runs in ${duration}ms (${runs.length ? runs.map((r) => r.id).join(",") : "-"})`
|
|
386
389
|
);
|
|
387
390
|
if (!runs?.length) {
|
|
388
391
|
return reject(new Error("No runs returned"));
|
|
@@ -1227,32 +1230,41 @@ function createServer(engine, options = {}) {
|
|
|
1227
1230
|
app.options = options;
|
|
1228
1231
|
app.execute = async ({ id, token }) => {
|
|
1229
1232
|
if (app.socket) {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1233
|
+
try {
|
|
1234
|
+
const start = Date.now();
|
|
1235
|
+
app.workflows[id] = true;
|
|
1236
|
+
const {
|
|
1237
|
+
channel: runChannel,
|
|
1238
|
+
plan,
|
|
1239
|
+
options: options2 = {},
|
|
1240
|
+
input
|
|
1241
|
+
} = await run_default(app.socket, token, id, logger2);
|
|
1242
|
+
if (!("payloadLimitMb" in options2)) {
|
|
1243
|
+
options2.payloadLimitMb = app.options.payloadLimitMb;
|
|
1244
|
+
}
|
|
1245
|
+
const onFinish = () => {
|
|
1246
|
+
const duration = (Date.now() - start) / 1e3;
|
|
1247
|
+
logger2.debug(
|
|
1248
|
+
`workflow ${id} complete in ${duration}s: releasing worker`
|
|
1249
|
+
);
|
|
1250
|
+
delete app.workflows[id];
|
|
1251
|
+
runChannel.leave();
|
|
1252
|
+
app.events.emit(INTERNAL_RUN_COMPLETE);
|
|
1253
|
+
};
|
|
1254
|
+
const context = execute(
|
|
1255
|
+
runChannel,
|
|
1256
|
+
engine,
|
|
1257
|
+
logger2,
|
|
1258
|
+
plan,
|
|
1259
|
+
input,
|
|
1260
|
+
options2,
|
|
1261
|
+
onFinish
|
|
1262
|
+
);
|
|
1263
|
+
app.workflows[id] = context;
|
|
1264
|
+
} catch (e) {
|
|
1265
|
+
logger2.error(`Unexpected error executing ${id}`);
|
|
1266
|
+
logger2.error(e);
|
|
1267
|
+
}
|
|
1256
1268
|
} else {
|
|
1257
1269
|
logger2.error("No lightning socket established");
|
|
1258
1270
|
}
|
|
@@ -6264,6 +6276,7 @@ function parseArgs(argv) {
|
|
|
6264
6276
|
// src/start.ts
|
|
6265
6277
|
var args = parseArgs(process.argv);
|
|
6266
6278
|
var logger = createLogger("SRV", { level: args.log });
|
|
6279
|
+
logger.info("Starting worker server...");
|
|
6267
6280
|
if (args.lightning === "mock") {
|
|
6268
6281
|
args.lightning = "ws://localhost:8888/worker";
|
|
6269
6282
|
if (!args.secret) {
|
|
@@ -6275,7 +6288,7 @@ if (args.lightning === "mock") {
|
|
|
6275
6288
|
}
|
|
6276
6289
|
var [minBackoff, maxBackoff] = args.backoff.split("/").map((n) => parseInt(n, 10) * 1e3);
|
|
6277
6290
|
function engineReady(engine) {
|
|
6278
|
-
logger.debug("Creating worker
|
|
6291
|
+
logger.debug("Creating worker instance");
|
|
6279
6292
|
const workerOptions = {
|
|
6280
6293
|
port: args.port,
|
|
6281
6294
|
lightning: args.lightning,
|
|
@@ -6306,6 +6319,7 @@ function engineReady(engine) {
|
|
|
6306
6319
|
} = workerOptions;
|
|
6307
6320
|
logger.debug("Worker options:", humanOptions);
|
|
6308
6321
|
server_default(engine, workerOptions);
|
|
6322
|
+
logger.success("Worker started OK");
|
|
6309
6323
|
}
|
|
6310
6324
|
if (args.mock) {
|
|
6311
6325
|
runtime_engine_default().then((engine) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/ws-worker",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"koa-logger": "^3.2.1",
|
|
23
23
|
"phoenix": "1.7.10",
|
|
24
24
|
"ws": "^8.18.0",
|
|
25
|
-
"@openfn/engine-multi": "1.2.
|
|
25
|
+
"@openfn/engine-multi": "1.2.5",
|
|
26
26
|
"@openfn/lexicon": "^1.1.0",
|
|
27
27
|
"@openfn/runtime": "1.4.2",
|
|
28
28
|
"@openfn/logger": "1.0.2"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"tsup": "^6.2.3",
|
|
43
43
|
"typescript": "^4.6.4",
|
|
44
44
|
"yargs": "^17.6.2",
|
|
45
|
-
"@openfn/lightning-mock": "2.0.
|
|
45
|
+
"@openfn/lightning-mock": "2.0.19"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"dist",
|