@openfn/ws-worker 1.6.7 → 1.8.0
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 +39 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +103 -19
- package/dist/start.js +131 -26
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# ws-worker
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fd0e499: Support collections
|
|
8
|
+
- bcd82e9: Accept collection version at startup (as arg or auto-looked-up from npm)
|
|
9
|
+
- Support @local adaptor versions (which map to the monorepo)
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1c79dc1: Append the collections adaptor to steps that need it
|
|
14
|
+
- b15f151: Update worker to use adaptors as an array on xplans. Internal only change.
|
|
15
|
+
- Updated dependencies [3463ff9]
|
|
16
|
+
- Updated dependencies [7245bf7]
|
|
17
|
+
- @openfn/runtime@1.5.0
|
|
18
|
+
- @openfn/engine-multi@1.4.0
|
|
19
|
+
|
|
20
|
+
## 1.7.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 1c79dc1: Append the collections adaptor to steps that need it
|
|
25
|
+
- b15f151: Update worker to use adaptors as an array on xplans. Internal only change.
|
|
26
|
+
- Updated dependencies [3463ff9]
|
|
27
|
+
- Updated dependencies [7245bf7]
|
|
28
|
+
- @openfn/runtime@2.0.0
|
|
29
|
+
- @openfn/engine-multi@1.4.0
|
|
30
|
+
|
|
31
|
+
## 1.7.0
|
|
32
|
+
|
|
33
|
+
### Minor Changes
|
|
34
|
+
|
|
35
|
+
- ae55a6a: Include timestamp on step complete even if the step failed
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [ae55a6a]
|
|
40
|
+
- @openfn/engine-multi@1.3.0
|
|
41
|
+
|
|
3
42
|
## 1.6.7
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,9 @@ declare type ServerOptions = {
|
|
|
74
74
|
};
|
|
75
75
|
socketTimeoutSeconds?: number;
|
|
76
76
|
payloadLimitMb?: number;
|
|
77
|
+
collectionsVersion?: string;
|
|
78
|
+
collectionsUrl?: string;
|
|
79
|
+
monorepoDir?: string;
|
|
77
80
|
};
|
|
78
81
|
interface ServerApp extends Koa {
|
|
79
82
|
id: string;
|
|
@@ -86,6 +89,7 @@ interface ServerApp extends Koa {
|
|
|
86
89
|
engine: RuntimeEngine;
|
|
87
90
|
options: ServerOptions;
|
|
88
91
|
workloop?: Workloop;
|
|
92
|
+
collectionsVersion?: string;
|
|
89
93
|
execute: ({ id, token }: ClaimRun) => Promise<void>;
|
|
90
94
|
destroy: () => void;
|
|
91
95
|
resumeWorkloop: () => void;
|
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.
|
|
32
|
+
version = "1.8.0";
|
|
33
33
|
description = "A Websocket Worker to connect Lightning to a Runtime Engine";
|
|
34
34
|
main = "dist/index.js";
|
|
35
35
|
type = "module";
|
|
@@ -107,6 +107,8 @@ var init_package = __esm({
|
|
|
107
107
|
|
|
108
108
|
// src/server.ts
|
|
109
109
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
110
|
+
import { promisify } from "node:util";
|
|
111
|
+
import { exec as _exec } from "node:child_process";
|
|
110
112
|
import Koa from "koa";
|
|
111
113
|
import bodyParser from "koa-bodyparser";
|
|
112
114
|
import koaLogger from "koa-logger";
|
|
@@ -316,6 +318,8 @@ var workloop_default = startWorkloop;
|
|
|
316
318
|
|
|
317
319
|
// src/util/convert-lightning-plan.ts
|
|
318
320
|
import crypto2 from "node:crypto";
|
|
321
|
+
import path from "node:path";
|
|
322
|
+
import { getNameAndVersion } from "@openfn/runtime";
|
|
319
323
|
var conditions = {
|
|
320
324
|
on_job_success: (upstreamId) => `Boolean(!state?.errors?.["${upstreamId}"] ?? true)`,
|
|
321
325
|
on_job_failure: (upstreamId) => `Boolean(state?.errors && state.errors["${upstreamId}"])`,
|
|
@@ -335,7 +339,37 @@ var mapTriggerEdgeCondition = (edge) => {
|
|
|
335
339
|
return true;
|
|
336
340
|
return condition;
|
|
337
341
|
};
|
|
338
|
-
var convert_lightning_plan_default = (run) => {
|
|
342
|
+
var convert_lightning_plan_default = (run, options = {}) => {
|
|
343
|
+
const { collectionsVersion, monorepoPath } = options;
|
|
344
|
+
const appendLocalVersions = (job) => {
|
|
345
|
+
if (monorepoPath && job.adaptors) {
|
|
346
|
+
for (const adaptor of job.adaptors) {
|
|
347
|
+
const { name: name2, version: version2 } = getNameAndVersion(adaptor);
|
|
348
|
+
if (monorepoPath && version2 === "local") {
|
|
349
|
+
const shortName = name2.replace("@openfn/language-", "");
|
|
350
|
+
const localPath = path.resolve(monorepoPath, "packages", shortName);
|
|
351
|
+
job.linker ??= {};
|
|
352
|
+
job.linker[name2] = {
|
|
353
|
+
path: localPath,
|
|
354
|
+
version: "local"
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return job;
|
|
360
|
+
};
|
|
361
|
+
const appendCollectionsAdaptor = (plan2, collectionsVersion2 = "latest") => {
|
|
362
|
+
let hasCollections;
|
|
363
|
+
plan2.workflow.steps.forEach((step) => {
|
|
364
|
+
const job = step;
|
|
365
|
+
if (job.expression?.match(/(collections\.)/)) {
|
|
366
|
+
hasCollections = true;
|
|
367
|
+
job.adaptors ??= [];
|
|
368
|
+
job.adaptors.push(`@openfn/language-collections@${collectionsVersion2}`);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
return hasCollections;
|
|
372
|
+
};
|
|
339
373
|
const runtimeOpts = {};
|
|
340
374
|
const engineOpts = {};
|
|
341
375
|
if (run.options) {
|
|
@@ -396,7 +430,7 @@ var convert_lightning_plan_default = (run) => {
|
|
|
396
430
|
id,
|
|
397
431
|
configuration: step.credential || step.credential_id,
|
|
398
432
|
expression: step.body,
|
|
399
|
-
|
|
433
|
+
adaptors: step.adaptor ? [step.adaptor] : []
|
|
400
434
|
};
|
|
401
435
|
if (step.name) {
|
|
402
436
|
job.name = step.name;
|
|
@@ -428,6 +462,21 @@ var convert_lightning_plan_default = (run) => {
|
|
|
428
462
|
if (run.name) {
|
|
429
463
|
plan.workflow.name = run.name;
|
|
430
464
|
}
|
|
465
|
+
if (collectionsVersion) {
|
|
466
|
+
const hasCollections = appendCollectionsAdaptor(
|
|
467
|
+
plan,
|
|
468
|
+
collectionsVersion
|
|
469
|
+
);
|
|
470
|
+
if (hasCollections) {
|
|
471
|
+
plan.workflow.credentials = {
|
|
472
|
+
collections_token: true,
|
|
473
|
+
collections_endpoint: true
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
for (const step of plan.workflow.steps) {
|
|
478
|
+
appendLocalVersions(step);
|
|
479
|
+
}
|
|
431
480
|
return {
|
|
432
481
|
plan,
|
|
433
482
|
options: engineOpts,
|
|
@@ -469,8 +518,8 @@ var create_run_state_default = (plan, input) => {
|
|
|
469
518
|
if (typeof input === "string") {
|
|
470
519
|
const jobs = plan.workflow.steps;
|
|
471
520
|
let startNode = jobs[0];
|
|
472
|
-
if (plan.options
|
|
473
|
-
startNode = jobs.find(({ id }) => id === plan.options
|
|
521
|
+
if (plan.options?.start) {
|
|
522
|
+
startNode = jobs.find(({ id }) => id === plan.options?.start);
|
|
474
523
|
}
|
|
475
524
|
const initialRuns = [];
|
|
476
525
|
if (startNode) {
|
|
@@ -910,9 +959,8 @@ var joinRunChannel = (socket, token, runId, logger) => {
|
|
|
910
959
|
if (!didReceiveOk) {
|
|
911
960
|
didReceiveOk = true;
|
|
912
961
|
logger.success(`connected to ${channelName}`, e);
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
resolve({ channel, plan, options, input });
|
|
962
|
+
const run = await get_with_reply_default(channel, GET_PLAN);
|
|
963
|
+
resolve({ channel, run });
|
|
916
964
|
}
|
|
917
965
|
}).receive("error", (err) => {
|
|
918
966
|
logger.error(`error connecting to ${channelName}`, err);
|
|
@@ -931,10 +979,6 @@ var joinRunChannel = (socket, token, runId, logger) => {
|
|
|
931
979
|
});
|
|
932
980
|
};
|
|
933
981
|
var run_default = joinRunChannel;
|
|
934
|
-
async function loadRun(channel) {
|
|
935
|
-
const runBody = await get_with_reply_default(channel, GET_PLAN);
|
|
936
|
-
return convert_lightning_plan_default(runBody);
|
|
937
|
-
}
|
|
938
982
|
|
|
939
983
|
// src/channels/worker-queue.ts
|
|
940
984
|
import EventEmitter from "node:events";
|
|
@@ -1008,6 +1052,7 @@ var connectToWorkerQueue = (endpoint, serverId, secret, timeout = 10, logger, So
|
|
|
1008
1052
|
var worker_queue_default = connectToWorkerQueue;
|
|
1009
1053
|
|
|
1010
1054
|
// src/server.ts
|
|
1055
|
+
var exec = promisify(_exec);
|
|
1011
1056
|
var DEFAULT_PORT = 2222;
|
|
1012
1057
|
var MIN_BACKOFF = 1e3;
|
|
1013
1058
|
var MAX_BACKOFF = 1e3 * 30;
|
|
@@ -1060,6 +1105,31 @@ function connect(app, logger, options = {}) {
|
|
|
1060
1105
|
logger
|
|
1061
1106
|
).on("connect", onConnect).on("disconnect", onDisconnect).on("error", onError);
|
|
1062
1107
|
}
|
|
1108
|
+
async function setupCollections(options, logger) {
|
|
1109
|
+
if (options.collectionsUrl) {
|
|
1110
|
+
logger.log("Using collections endpoint at ", options.collectionsUrl);
|
|
1111
|
+
} else {
|
|
1112
|
+
logger.warn(
|
|
1113
|
+
"WARNING: no collections URL provided. Collections service will not be enabled."
|
|
1114
|
+
);
|
|
1115
|
+
logger.warn(
|
|
1116
|
+
"Pass --collections-version or set WORKER_COLLECTIONS_URL to set the url"
|
|
1117
|
+
);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
if (options.collectionsVersion && options.collectionsVersion !== "latest") {
|
|
1121
|
+
logger.log(
|
|
1122
|
+
"Using collections version from CLI/env: ",
|
|
1123
|
+
options.collectionsVersion
|
|
1124
|
+
);
|
|
1125
|
+
return options.collectionsVersion;
|
|
1126
|
+
}
|
|
1127
|
+
const { stdout: version2 } = await exec(
|
|
1128
|
+
"npm view @openfn/language-collections@latest version"
|
|
1129
|
+
);
|
|
1130
|
+
logger.log("Using collections version from @latest: ", version2);
|
|
1131
|
+
return version2;
|
|
1132
|
+
}
|
|
1063
1133
|
function createServer(engine, options = {}) {
|
|
1064
1134
|
const logger = options.logger || createMockLogger2();
|
|
1065
1135
|
const port = options.port || DEFAULT_PORT;
|
|
@@ -1102,12 +1172,23 @@ function createServer(engine, options = {}) {
|
|
|
1102
1172
|
try {
|
|
1103
1173
|
const start = Date.now();
|
|
1104
1174
|
app.workflows[id] = true;
|
|
1105
|
-
const {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1175
|
+
const { channel: runChannel, run } = await run_default(
|
|
1176
|
+
app.socket,
|
|
1177
|
+
token,
|
|
1178
|
+
id,
|
|
1179
|
+
logger
|
|
1180
|
+
);
|
|
1181
|
+
const { plan, options: options2, input } = convert_lightning_plan_default(run, {
|
|
1182
|
+
collectionsVersion: app.options.collectionsVersion,
|
|
1183
|
+
monorepoPath: app.options.monorepoDir
|
|
1184
|
+
});
|
|
1185
|
+
logger.debug("converted run body into execution plan:", plan);
|
|
1186
|
+
if (plan.workflow.credentials?.collections_token) {
|
|
1187
|
+
plan.workflow.credentials.collections_token = token;
|
|
1188
|
+
}
|
|
1189
|
+
if (plan.workflow.credentials?.collections_endpoint) {
|
|
1190
|
+
plan.workflow.credentials.collections_endpoint = app.options.collectionsUrl;
|
|
1191
|
+
}
|
|
1111
1192
|
if (!("payloadLimitMb" in options2)) {
|
|
1112
1193
|
options2.payloadLimitMb = app.options.payloadLimitMb;
|
|
1113
1194
|
}
|
|
@@ -1156,7 +1237,10 @@ function createServer(engine, options = {}) {
|
|
|
1156
1237
|
app.destroy = () => destroy_default(app, logger);
|
|
1157
1238
|
app.use(router.routes());
|
|
1158
1239
|
if (options.lightning) {
|
|
1159
|
-
|
|
1240
|
+
setupCollections(options, logger).then((version2) => {
|
|
1241
|
+
app.collectionsVersion = version2;
|
|
1242
|
+
connect(app, logger, options);
|
|
1243
|
+
});
|
|
1160
1244
|
} else {
|
|
1161
1245
|
logger.warn("No lightning URL provided");
|
|
1162
1246
|
}
|
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.
|
|
40
|
+
version = "1.8.0";
|
|
41
41
|
description = "A Websocket Worker to connect Lightning to a Runtime Engine";
|
|
42
42
|
main = "dist/index.js";
|
|
43
43
|
type = "module";
|
|
@@ -246,6 +246,8 @@ var runtime_engine_default = createMock;
|
|
|
246
246
|
|
|
247
247
|
// src/server.ts
|
|
248
248
|
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
249
|
+
import { promisify } from "node:util";
|
|
250
|
+
import { exec as _exec } from "node:child_process";
|
|
249
251
|
import Koa from "koa";
|
|
250
252
|
import bodyParser from "koa-bodyparser";
|
|
251
253
|
import koaLogger from "koa-logger";
|
|
@@ -455,6 +457,8 @@ var workloop_default = startWorkloop;
|
|
|
455
457
|
|
|
456
458
|
// src/util/convert-lightning-plan.ts
|
|
457
459
|
import crypto3 from "node:crypto";
|
|
460
|
+
import path from "node:path";
|
|
461
|
+
import { getNameAndVersion } from "@openfn/runtime";
|
|
458
462
|
var conditions = {
|
|
459
463
|
on_job_success: (upstreamId) => `Boolean(!state?.errors?.["${upstreamId}"] ?? true)`,
|
|
460
464
|
on_job_failure: (upstreamId) => `Boolean(state?.errors && state.errors["${upstreamId}"])`,
|
|
@@ -474,7 +478,37 @@ var mapTriggerEdgeCondition = (edge) => {
|
|
|
474
478
|
return true;
|
|
475
479
|
return condition;
|
|
476
480
|
};
|
|
477
|
-
var convert_lightning_plan_default = (run2) => {
|
|
481
|
+
var convert_lightning_plan_default = (run2, options = {}) => {
|
|
482
|
+
const { collectionsVersion, monorepoPath } = options;
|
|
483
|
+
const appendLocalVersions = (job) => {
|
|
484
|
+
if (monorepoPath && job.adaptors) {
|
|
485
|
+
for (const adaptor of job.adaptors) {
|
|
486
|
+
const { name: name2, version: version2 } = getNameAndVersion(adaptor);
|
|
487
|
+
if (monorepoPath && version2 === "local") {
|
|
488
|
+
const shortName = name2.replace("@openfn/language-", "");
|
|
489
|
+
const localPath = path.resolve(monorepoPath, "packages", shortName);
|
|
490
|
+
job.linker ??= {};
|
|
491
|
+
job.linker[name2] = {
|
|
492
|
+
path: localPath,
|
|
493
|
+
version: "local"
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return job;
|
|
499
|
+
};
|
|
500
|
+
const appendCollectionsAdaptor = (plan2, collectionsVersion2 = "latest") => {
|
|
501
|
+
let hasCollections;
|
|
502
|
+
plan2.workflow.steps.forEach((step) => {
|
|
503
|
+
const job = step;
|
|
504
|
+
if (job.expression?.match(/(collections\.)/)) {
|
|
505
|
+
hasCollections = true;
|
|
506
|
+
job.adaptors ??= [];
|
|
507
|
+
job.adaptors.push(`@openfn/language-collections@${collectionsVersion2}`);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
return hasCollections;
|
|
511
|
+
};
|
|
478
512
|
const runtimeOpts = {};
|
|
479
513
|
const engineOpts = {};
|
|
480
514
|
if (run2.options) {
|
|
@@ -535,7 +569,7 @@ var convert_lightning_plan_default = (run2) => {
|
|
|
535
569
|
id,
|
|
536
570
|
configuration: step.credential || step.credential_id,
|
|
537
571
|
expression: step.body,
|
|
538
|
-
|
|
572
|
+
adaptors: step.adaptor ? [step.adaptor] : []
|
|
539
573
|
};
|
|
540
574
|
if (step.name) {
|
|
541
575
|
job.name = step.name;
|
|
@@ -567,6 +601,21 @@ var convert_lightning_plan_default = (run2) => {
|
|
|
567
601
|
if (run2.name) {
|
|
568
602
|
plan.workflow.name = run2.name;
|
|
569
603
|
}
|
|
604
|
+
if (collectionsVersion) {
|
|
605
|
+
const hasCollections = appendCollectionsAdaptor(
|
|
606
|
+
plan,
|
|
607
|
+
collectionsVersion
|
|
608
|
+
);
|
|
609
|
+
if (hasCollections) {
|
|
610
|
+
plan.workflow.credentials = {
|
|
611
|
+
collections_token: true,
|
|
612
|
+
collections_endpoint: true
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
for (const step of plan.workflow.steps) {
|
|
617
|
+
appendLocalVersions(step);
|
|
618
|
+
}
|
|
570
619
|
return {
|
|
571
620
|
plan,
|
|
572
621
|
options: engineOpts,
|
|
@@ -608,8 +657,8 @@ var create_run_state_default = (plan, input) => {
|
|
|
608
657
|
if (typeof input === "string") {
|
|
609
658
|
const jobs = plan.workflow.steps;
|
|
610
659
|
let startNode = jobs[0];
|
|
611
|
-
if (plan.options
|
|
612
|
-
startNode = jobs.find(({ id }) => id === plan.options
|
|
660
|
+
if (plan.options?.start) {
|
|
661
|
+
startNode = jobs.find(({ id }) => id === plan.options?.start);
|
|
613
662
|
}
|
|
614
663
|
const initialRuns = [];
|
|
615
664
|
if (startNode) {
|
|
@@ -1049,9 +1098,8 @@ var joinRunChannel = (socket, token, runId, logger2) => {
|
|
|
1049
1098
|
if (!didReceiveOk) {
|
|
1050
1099
|
didReceiveOk = true;
|
|
1051
1100
|
logger2.success(`connected to ${channelName}`, e);
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
resolve5({ channel, plan, options, input });
|
|
1101
|
+
const run2 = await get_with_reply_default(channel, GET_PLAN);
|
|
1102
|
+
resolve5({ channel, run: run2 });
|
|
1055
1103
|
}
|
|
1056
1104
|
}).receive("error", (err) => {
|
|
1057
1105
|
logger2.error(`error connecting to ${channelName}`, err);
|
|
@@ -1070,10 +1118,6 @@ var joinRunChannel = (socket, token, runId, logger2) => {
|
|
|
1070
1118
|
});
|
|
1071
1119
|
};
|
|
1072
1120
|
var run_default = joinRunChannel;
|
|
1073
|
-
async function loadRun(channel) {
|
|
1074
|
-
const runBody = await get_with_reply_default(channel, GET_PLAN);
|
|
1075
|
-
return convert_lightning_plan_default(runBody);
|
|
1076
|
-
}
|
|
1077
1121
|
|
|
1078
1122
|
// src/channels/worker-queue.ts
|
|
1079
1123
|
import EventEmitter2 from "node:events";
|
|
@@ -1147,6 +1191,7 @@ var connectToWorkerQueue = (endpoint, serverId, secret, timeout = 10, logger2, S
|
|
|
1147
1191
|
var worker_queue_default = connectToWorkerQueue;
|
|
1148
1192
|
|
|
1149
1193
|
// src/server.ts
|
|
1194
|
+
var exec = promisify(_exec);
|
|
1150
1195
|
var DEFAULT_PORT = 2222;
|
|
1151
1196
|
var MIN_BACKOFF = 1e3;
|
|
1152
1197
|
var MAX_BACKOFF = 1e3 * 30;
|
|
@@ -1199,6 +1244,31 @@ function connect(app, logger2, options = {}) {
|
|
|
1199
1244
|
logger2
|
|
1200
1245
|
).on("connect", onConnect).on("disconnect", onDisconnect).on("error", onError);
|
|
1201
1246
|
}
|
|
1247
|
+
async function setupCollections(options, logger2) {
|
|
1248
|
+
if (options.collectionsUrl) {
|
|
1249
|
+
logger2.log("Using collections endpoint at ", options.collectionsUrl);
|
|
1250
|
+
} else {
|
|
1251
|
+
logger2.warn(
|
|
1252
|
+
"WARNING: no collections URL provided. Collections service will not be enabled."
|
|
1253
|
+
);
|
|
1254
|
+
logger2.warn(
|
|
1255
|
+
"Pass --collections-version or set WORKER_COLLECTIONS_URL to set the url"
|
|
1256
|
+
);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (options.collectionsVersion && options.collectionsVersion !== "latest") {
|
|
1260
|
+
logger2.log(
|
|
1261
|
+
"Using collections version from CLI/env: ",
|
|
1262
|
+
options.collectionsVersion
|
|
1263
|
+
);
|
|
1264
|
+
return options.collectionsVersion;
|
|
1265
|
+
}
|
|
1266
|
+
const { stdout: version2 } = await exec(
|
|
1267
|
+
"npm view @openfn/language-collections@latest version"
|
|
1268
|
+
);
|
|
1269
|
+
logger2.log("Using collections version from @latest: ", version2);
|
|
1270
|
+
return version2;
|
|
1271
|
+
}
|
|
1202
1272
|
function createServer(engine, options = {}) {
|
|
1203
1273
|
const logger2 = options.logger || createMockLogger2();
|
|
1204
1274
|
const port = options.port || DEFAULT_PORT;
|
|
@@ -1241,12 +1311,23 @@ function createServer(engine, options = {}) {
|
|
|
1241
1311
|
try {
|
|
1242
1312
|
const start = Date.now();
|
|
1243
1313
|
app.workflows[id] = true;
|
|
1244
|
-
const {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1314
|
+
const { channel: runChannel, run: run2 } = await run_default(
|
|
1315
|
+
app.socket,
|
|
1316
|
+
token,
|
|
1317
|
+
id,
|
|
1318
|
+
logger2
|
|
1319
|
+
);
|
|
1320
|
+
const { plan, options: options2, input } = convert_lightning_plan_default(run2, {
|
|
1321
|
+
collectionsVersion: app.options.collectionsVersion,
|
|
1322
|
+
monorepoPath: app.options.monorepoDir
|
|
1323
|
+
});
|
|
1324
|
+
logger2.debug("converted run body into execution plan:", plan);
|
|
1325
|
+
if (plan.workflow.credentials?.collections_token) {
|
|
1326
|
+
plan.workflow.credentials.collections_token = token;
|
|
1327
|
+
}
|
|
1328
|
+
if (plan.workflow.credentials?.collections_endpoint) {
|
|
1329
|
+
plan.workflow.credentials.collections_endpoint = app.options.collectionsUrl;
|
|
1330
|
+
}
|
|
1250
1331
|
if (!("payloadLimitMb" in options2)) {
|
|
1251
1332
|
options2.payloadLimitMb = app.options.payloadLimitMb;
|
|
1252
1333
|
}
|
|
@@ -1295,7 +1376,10 @@ function createServer(engine, options = {}) {
|
|
|
1295
1376
|
app.destroy = () => destroy_default(app, logger2);
|
|
1296
1377
|
app.use(router.routes());
|
|
1297
1378
|
if (options.lightning) {
|
|
1298
|
-
|
|
1379
|
+
setupCollections(options, logger2).then((version2) => {
|
|
1380
|
+
app.collectionsVersion = version2;
|
|
1381
|
+
connect(app, logger2, options);
|
|
1382
|
+
});
|
|
1299
1383
|
} else {
|
|
1300
1384
|
logger2.warn("No lightning URL provided");
|
|
1301
1385
|
}
|
|
@@ -2591,11 +2675,11 @@ var parser = new YargsParser({
|
|
|
2591
2675
|
format,
|
|
2592
2676
|
normalize,
|
|
2593
2677
|
resolve: resolve2,
|
|
2594
|
-
require: (
|
|
2678
|
+
require: (path2) => {
|
|
2595
2679
|
if (typeof __require !== "undefined") {
|
|
2596
|
-
return __require(
|
|
2597
|
-
} else if (
|
|
2598
|
-
return JSON.parse(readFileSync(
|
|
2680
|
+
return __require(path2);
|
|
2681
|
+
} else if (path2.match(/\.json$/)) {
|
|
2682
|
+
return JSON.parse(readFileSync(path2, "utf8"));
|
|
2599
2683
|
} else {
|
|
2600
2684
|
throw Error("only .json config files are supported in ESM");
|
|
2601
2685
|
}
|
|
@@ -6186,6 +6270,8 @@ function parseArgs(argv) {
|
|
|
6186
6270
|
const {
|
|
6187
6271
|
WORKER_BACKOFF,
|
|
6188
6272
|
WORKER_CAPACITY,
|
|
6273
|
+
WORKER_COLLECTIONS_VERSION,
|
|
6274
|
+
WORKER_COLLECTIONS_URL,
|
|
6189
6275
|
WORKER_LIGHTNING_PUBLIC_KEY,
|
|
6190
6276
|
WORKER_LIGHTNING_SERVICE_URL,
|
|
6191
6277
|
WORKER_LOG_LEVEL,
|
|
@@ -6196,7 +6282,8 @@ function parseArgs(argv) {
|
|
|
6196
6282
|
WORKER_REPO_DIR,
|
|
6197
6283
|
WORKER_SECRET,
|
|
6198
6284
|
WORKER_STATE_PROPS_TO_REMOVE,
|
|
6199
|
-
WORKER_SOCKET_TIMEOUT_SECONDS
|
|
6285
|
+
WORKER_SOCKET_TIMEOUT_SECONDS,
|
|
6286
|
+
OPENFN_ADAPTORS_REPO
|
|
6200
6287
|
} = process.env;
|
|
6201
6288
|
const parser2 = yargs_default(hideBin(argv)).command("server", "Start a ws-worker server").option("port", {
|
|
6202
6289
|
alias: "p",
|
|
@@ -6208,6 +6295,9 @@ function parseArgs(argv) {
|
|
|
6208
6295
|
}).option("repo-dir", {
|
|
6209
6296
|
alias: "d",
|
|
6210
6297
|
description: "Path to the runtime repo (where modules will be installed). Env: WORKER_REPO_DIR"
|
|
6298
|
+
}).option("monorepo-dir", {
|
|
6299
|
+
alias: "m",
|
|
6300
|
+
description: "Path to the adaptors mono repo, from where @local adaptors will be loaded. Env: OPENFN_ADAPTORS_REPO"
|
|
6211
6301
|
}).option("secret", {
|
|
6212
6302
|
alias: "s",
|
|
6213
6303
|
description: "Worker secret. (comes from WORKER_SECRET by default). Env: WORKER_SECRET"
|
|
@@ -6243,6 +6333,12 @@ function parseArgs(argv) {
|
|
|
6243
6333
|
alias: "t",
|
|
6244
6334
|
description: "Default run timeout for the server, in seconds. Env: WORKER_MAX_RUN_DURATION_SECONDS",
|
|
6245
6335
|
type: "number"
|
|
6336
|
+
}).option("collections-url", {
|
|
6337
|
+
alias: ["c"],
|
|
6338
|
+
description: "URL to the Collections service endpoint. Required for Collections, eg, https://app.openfn.org/collections. Env: WORKER_COLLECTIONS_URL"
|
|
6339
|
+
}).option("collections-version", {
|
|
6340
|
+
description: "The version of the collections adaptor to use for all runs on this worker instance.Env: WORKER_COLLECTIONS_VERSION",
|
|
6341
|
+
type: "string"
|
|
6246
6342
|
});
|
|
6247
6343
|
const args2 = parser2.parse();
|
|
6248
6344
|
return {
|
|
@@ -6254,6 +6350,7 @@ function parseArgs(argv) {
|
|
|
6254
6350
|
"ws://localhost:4000/worker"
|
|
6255
6351
|
),
|
|
6256
6352
|
repoDir: setArg(args2.repoDir, WORKER_REPO_DIR),
|
|
6353
|
+
monorepoDir: setArg(args2.monorepoDir, OPENFN_ADAPTORS_REPO),
|
|
6257
6354
|
secret: setArg(args2.secret, WORKER_SECRET),
|
|
6258
6355
|
lightningPublicKey: setArg(
|
|
6259
6356
|
args2.lightningPublicKey,
|
|
@@ -6278,7 +6375,12 @@ function parseArgs(argv) {
|
|
|
6278
6375
|
args2.socketTimeoutSeconds,
|
|
6279
6376
|
WORKER_SOCKET_TIMEOUT_SECONDS,
|
|
6280
6377
|
DEFAULT_SOCKET_TIMEOUT_SECONDS
|
|
6281
|
-
)
|
|
6378
|
+
),
|
|
6379
|
+
collectionsVersion: setArg(
|
|
6380
|
+
args2.collectionsVersion,
|
|
6381
|
+
WORKER_COLLECTIONS_VERSION
|
|
6382
|
+
),
|
|
6383
|
+
collectionsUrl: setArg(args2.collectionsUrl, WORKER_COLLECTIONS_URL)
|
|
6282
6384
|
};
|
|
6283
6385
|
}
|
|
6284
6386
|
|
|
@@ -6309,7 +6411,10 @@ function engineReady(engine) {
|
|
|
6309
6411
|
max: maxBackoff
|
|
6310
6412
|
},
|
|
6311
6413
|
maxWorkflows: args.capacity,
|
|
6312
|
-
payloadLimitMb: args.payloadMemory
|
|
6414
|
+
payloadLimitMb: args.payloadMemory,
|
|
6415
|
+
collectionsVersion: args.collectionsVersion,
|
|
6416
|
+
collectionsUrl: args.collectionsUrl,
|
|
6417
|
+
monorepoDir: args.monorepoDir
|
|
6313
6418
|
};
|
|
6314
6419
|
if (args.lightningPublicKey) {
|
|
6315
6420
|
logger.info(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/ws-worker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"koa-logger": "^3.2.1",
|
|
23
23
|
"phoenix": "1.7.10",
|
|
24
24
|
"ws": "^8.18.0",
|
|
25
|
-
"@openfn/engine-multi": "1.
|
|
25
|
+
"@openfn/engine-multi": "1.4.0",
|
|
26
26
|
"@openfn/lexicon": "^1.1.0",
|
|
27
27
|
"@openfn/logger": "1.0.2",
|
|
28
|
-
"@openfn/runtime": "1.
|
|
28
|
+
"@openfn/runtime": "1.5.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/koa": "^2.13.5",
|
|
@@ -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.21"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"dist",
|