@lango-project/lango-boss 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +111 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +725 -0
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/boss.mjs +136 -0
- package/dist/boss.mjs.map +1 -0
- package/dist/claim_watch.mjs +99 -0
- package/dist/claim_watch.mjs.map +1 -0
- package/dist/cli.mjs +143 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/configuration.mjs +58 -0
- package/dist/configuration.mjs.map +1 -0
- package/dist/dispatcher.mjs +108 -0
- package/dist/dispatcher.mjs.map +1 -0
- package/dist/driver.mjs +98 -0
- package/dist/driver.mjs.map +1 -0
- package/dist/envelope.mjs +92 -0
- package/dist/envelope.mjs.map +1 -0
- package/dist/library.mjs +139 -0
- package/dist/library.mjs.map +1 -0
- package/dist/management.mjs +360 -0
- package/dist/management.mjs.map +1 -0
- package/dist/management_transaction.mjs +26 -0
- package/dist/management_transaction.mjs.map +1 -0
- package/dist/namespace.mjs +27 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/queue.mjs +161 -0
- package/dist/queue.mjs.map +1 -0
- package/dist/reads.mjs +359 -0
- package/dist/reads.mjs.map +1 -0
- package/dist/retention.mjs +133 -0
- package/dist/retention.mjs.map +1 -0
- package/dist/schedule_sync.mjs +222 -0
- package/dist/schedule_sync.mjs.map +1 -0
- package/dist/schedule_transaction.mjs +24 -0
- package/dist/schedule_transaction.mjs.map +1 -0
- package/dist/schedules.mjs +201 -0
- package/dist/schedules.mjs.map +1 -0
- package/dist/transaction.mjs +16 -0
- package/dist/transaction.mjs.map +1 -0
- package/dist/validation.mjs +90 -0
- package/dist/validation.mjs.map +1 -0
- package/dist/worker.mjs +316 -0
- package/dist/worker.mjs.map +1 -0
- package/docs/guide.md +88 -0
- package/docs/management.md +93 -0
- package/docs/producer.md +115 -0
- package/docs/reads.md +107 -0
- package/docs/reference.md +77 -0
- package/docs/release.md +103 -0
- package/docs/retention.md +47 -0
- package/docs/scheduling.md +79 -0
- package/docs/worker.md +90 -0
- package/examples/reports/README.md +118 -0
- package/examples/reports/app.lango +133 -0
- package/examples/reports/deploy.xml +6 -0
- package/examples/reports/dist/.lango/bignumber.mjs +3119 -0
- package/examples/reports/dist/.lango/localization.mjs +108 -0
- package/examples/reports/dist/.lango/runtime.mjs +725 -0
- package/examples/reports/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/examples/reports/dist/.lango/vendor/i18next.mjs +2434 -0
- package/examples/reports/dist/.lango/xmldom/conventions.js +429 -0
- package/examples/reports/dist/.lango/xmldom/dom-parser.js +591 -0
- package/examples/reports/dist/.lango/xmldom/dom.js +3759 -0
- package/examples/reports/dist/.lango/xmldom/entities.js +2171 -0
- package/examples/reports/dist/.lango/xmldom/errors.js +205 -0
- package/examples/reports/dist/.lango/xmldom/grammar.js +559 -0
- package/examples/reports/dist/.lango/xmldom/index.js +41 -0
- package/examples/reports/dist/.lango/xmldom/package.json +1 -0
- package/examples/reports/dist/.lango/xmldom/sax.js +983 -0
- package/examples/reports/dist/.lango/xmldom.LICENSE.md +8 -0
- package/examples/reports/dist/app.mjs +137 -0
- package/examples/reports/dist/app.mjs.map +1 -0
- package/examples/reports/dist/handlers.mjs +202 -0
- package/examples/reports/dist/handlers.mjs.map +1 -0
- package/examples/reports/dist/setup.mjs +14 -0
- package/examples/reports/dist/setup.mjs.map +1 -0
- package/examples/reports/handlers.lango +153 -0
- package/examples/reports/jobs.xml +5 -0
- package/examples/reports/package.json +23 -0
- package/examples/reports/routes.xml +4 -0
- package/examples/reports/setup.lango +17 -0
- package/package.json +60 -4
- package/src/boss.lango +92 -0
- package/src/claim_watch.lango +58 -0
- package/src/cli.lango +103 -0
- package/src/configuration.lango +43 -0
- package/src/dispatcher.lango +75 -0
- package/src/driver.lango +72 -0
- package/src/envelope.lango +56 -0
- package/src/library.lango +66 -0
- package/src/management.lango +302 -0
- package/src/management_transaction.lango +28 -0
- package/src/namespace.lango +15 -0
- package/src/queue.lango +115 -0
- package/src/reads.lango +277 -0
- package/src/retention.lango +107 -0
- package/src/schedule_sync.lango +190 -0
- package/src/schedule_transaction.lango +22 -0
- package/src/schedules.lango +165 -0
- package/src/transaction.lango +23 -0
- package/src/validation.lango +45 -0
- package/src/worker.lango +230 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2019 - present Christopher J. Brody and other contributors, as listed in: https://github.com/xmldom/xmldom/graphs/contributors
|
|
2
|
+
Copyright 2012 - 2017 @jindw <jindw@xidea.org> and other contributors, as listed in: https://github.com/jindw/xmldom/graphs/contributors
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/boss.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { loadConfiguration } from "./configuration.mjs";
|
|
2
|
+
import { createDriver, prepareQueues, queueProvider } from "./driver.mjs";
|
|
3
|
+
import { prepareManagement } from "./management.mjs";
|
|
4
|
+
import * as server from "@lango-project/lango-server";
|
|
5
|
+
import {
|
|
6
|
+
hostGlobal as __hostGlobal,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
8
|
+
isNumber as __isNumber,
|
|
9
|
+
isString as __isString,
|
|
10
|
+
isBool as __isBool,
|
|
11
|
+
isObject as __isObject,
|
|
12
|
+
isArray as __isArray,
|
|
13
|
+
requireBoolean as __requireBoolean,
|
|
14
|
+
normalize as __normalize,
|
|
15
|
+
boundary as __boundary,
|
|
16
|
+
requireArity as __requireArity,
|
|
17
|
+
withArity as __withArity,
|
|
18
|
+
} from "./.lango/runtime.mjs";
|
|
19
|
+
|
|
20
|
+
export class Boss {
|
|
21
|
+
#config;
|
|
22
|
+
#state;
|
|
23
|
+
#driver;
|
|
24
|
+
#starting;
|
|
25
|
+
#closing;
|
|
26
|
+
constructor(directory) {
|
|
27
|
+
__requireArity(arguments.length, [0], "constructor");
|
|
28
|
+
directory = __boundary(directory);
|
|
29
|
+
this.#config = loadConfiguration(directory);
|
|
30
|
+
this.#state = "new";
|
|
31
|
+
this.#driver = null;
|
|
32
|
+
this.#starting = null;
|
|
33
|
+
this.#closing = null;
|
|
34
|
+
}
|
|
35
|
+
start() {
|
|
36
|
+
if (__requireBoolean(__normalize(this.#state) !== "new")) {
|
|
37
|
+
return __normalize(__hostGlobal(["Promise"]).reject("Boss can only be started once"));
|
|
38
|
+
}
|
|
39
|
+
this.#state = "starting";
|
|
40
|
+
this.#driver = createDriver(__normalize(this.#config));
|
|
41
|
+
this.#starting = this.#prepare();
|
|
42
|
+
return __normalize(this.#starting);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
#prepare() {
|
|
46
|
+
return __normalize(this.#driver.start()).then(__withArity(__bindContexts((ignored) => {
|
|
47
|
+
ignored = __boundary(ignored);
|
|
48
|
+
return prepareQueues(__normalize(this.#driver), __normalize(this.#config.targets));
|
|
49
|
+
return null;
|
|
50
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
51
|
+
ignored = __boundary(ignored);
|
|
52
|
+
return prepareManagement(__normalize(this.#config));
|
|
53
|
+
return null;
|
|
54
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
55
|
+
ignored = __boundary(ignored);
|
|
56
|
+
if (__requireBoolean(__normalize(this.#state) !== "starting")) {
|
|
57
|
+
throw "Boss closed during startup";
|
|
58
|
+
}
|
|
59
|
+
this.#state = "running";
|
|
60
|
+
return null;
|
|
61
|
+
return null;
|
|
62
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
63
|
+
error = __boundary(error);
|
|
64
|
+
return __normalize(this.#driver.stop()).then(__withArity(__bindContexts((ignored) => {
|
|
65
|
+
ignored = __boundary(ignored);
|
|
66
|
+
this.#state = "closed";
|
|
67
|
+
throw error;
|
|
68
|
+
return null;
|
|
69
|
+
}), [0], "closure"));
|
|
70
|
+
return null;
|
|
71
|
+
}), [0], "closure"));
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
#provider() {
|
|
75
|
+
return queueProvider(__normalize(this.#config));
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
configure(builder) {
|
|
79
|
+
__requireArity(arguments.length, [0], "configure");
|
|
80
|
+
builder = __boundary(builder);
|
|
81
|
+
if (__requireBoolean(__normalize(this.#state) !== "running")) {
|
|
82
|
+
throw "Start Boss before configuring queue submission";
|
|
83
|
+
}
|
|
84
|
+
__normalize(builder.provideQueue(this.#provider()));
|
|
85
|
+
return builder;
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
executor(settings) {
|
|
89
|
+
__requireArity(arguments.length, [0], "executor");
|
|
90
|
+
settings = __boundary(settings);
|
|
91
|
+
if (__requireBoolean(__normalize(this.#state) !== "running")) {
|
|
92
|
+
throw "Start Boss before creating an executor";
|
|
93
|
+
}
|
|
94
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(settings === null) || __requireBoolean(!__requireBoolean(__isObject(settings)))) || __requireBoolean(__isArray(settings))) || __requireBoolean(__normalize(settings.queueProvider) !== null))) {
|
|
95
|
+
throw "Executor requires settings without a separate queue provider";
|
|
96
|
+
}
|
|
97
|
+
let options = __normalize(__hostGlobal(["Object"]).assign({ }, settings, { queueProvider: this.#provider() }));
|
|
98
|
+
return new server.Executor(__normalize(this.#config.root), options);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
close() {
|
|
102
|
+
if (__requireBoolean(__normalize(this.#closing) !== null)) {
|
|
103
|
+
return __normalize(this.#closing);
|
|
104
|
+
}
|
|
105
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#state) === "new") || __requireBoolean(__normalize(this.#state) === "closed"))) {
|
|
106
|
+
this.#state = "closed";
|
|
107
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
108
|
+
}
|
|
109
|
+
this.#state = "closing";
|
|
110
|
+
let pending = __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
111
|
+
if (__requireBoolean(__normalize(this.#starting) !== null)) {
|
|
112
|
+
pending = __normalize(this.#starting);
|
|
113
|
+
}
|
|
114
|
+
this.#closing = this.#closeAfter(pending);
|
|
115
|
+
return __normalize(this.#closing);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
#closeAfter(pending) {
|
|
119
|
+
__requireArity(arguments.length, [0], "closeAfter");
|
|
120
|
+
pending = __boundary(pending);
|
|
121
|
+
return pending.catch(__withArity(__bindContexts((error) => {
|
|
122
|
+
error = __boundary(error);
|
|
123
|
+
return null;
|
|
124
|
+
return null;
|
|
125
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
126
|
+
ignored = __boundary(ignored);
|
|
127
|
+
return __normalize(this.#driver.stop());
|
|
128
|
+
return null;
|
|
129
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
130
|
+
this.#state = "closed";
|
|
131
|
+
return null;
|
|
132
|
+
}));
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=boss.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boss.mjs","sources":["boss.lango"],"sourcesContent":["import \"./configuration\"\n loadConfiguration(directory)\nimport \"./driver\"\n createDriver(config, consumer = false, scheduling = false, cronMonitorIntervalSeconds = 30)\n prepareQueues(driver, targets)\n queueProvider(config)\nimport js \"@lango-project/lango-server\" as server\nimport \"./management\"\n prepareManagement(config)\nimport js global Promise\nimport js global Object\n\nexport class Boss(directory)\n methods\n start()\n close()\n configure(builder)\n executor(settings)\n\nBoss(directory)\n @config = loadConfiguration(directory)\n @state = \"new\"\n @driver = null\n @starting = null\n @closing = null\n\nBoss:start()\n if @state != \"new\"\n return Promise/reject(\"Boss can only be started once\")\n @state = \"starting\"\n @driver = createDriver(@config)\n @starting = prepare()\n return @starting\n\nBoss:prepare()\n return chain @driver.start()\n then(ignored)\n return prepareQueues(@driver, @config.targets)\n then(ignored)\n return prepareManagement(@config)\n then(ignored)\n if @state != \"starting\"\n throw \"Boss closed during startup\"\n @state = \"running\"\n return null\n catch(error)\n return chain @driver.stop()\n then(ignored)\n capture error\n @state = \"closed\"\n throw error\n\nBoss:provider()\n return queueProvider(@config)\n\nBoss:configure(builder)\n if @state != \"running\"\n throw \"Start Boss before configuring queue submission\"\n builder.provideQueue(provider())\n return builder\n\nBoss:executor(settings)\n if @state != \"running\"\n throw \"Start Boss before creating an executor\"\n if settings == null or !is_object(settings) or is_array(settings) or settings.queueProvider != null\n throw \"Executor requires settings without a separate queue provider\"\n options = Object/assign({}, settings, {\n queueProvider: provider()\n })\n return new server/Executor(@config.root, options)\n\nBoss:close()\n if @closing != null\n return @closing\n if @state == \"new\" or @state == \"closed\"\n @state = \"closed\"\n return Promise/resolve(null)\n @state = \"closing\"\n pending = Promise/resolve(null)\n if @starting != null\n pending = @starting\n @closing = closeAfter(pending)\n return @closing\n\nBoss:closeAfter(pending)\n return chain pending\n catch(error)\n return null\n then(ignored)\n return @driver.stop()\n finally\n @state = \"closed\"\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostGlobal as __hostGlobal,
|
|
3
|
+
hostGlobalCall as __hostGlobalCall,
|
|
4
|
+
contextGet as __contextGet,
|
|
5
|
+
contextSet as __contextSet,
|
|
6
|
+
contextRestore as __contextRestore,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
8
|
+
requireBoolean as __requireBoolean,
|
|
9
|
+
normalize as __normalize,
|
|
10
|
+
boundary as __boundary,
|
|
11
|
+
requireArity as __requireArity,
|
|
12
|
+
withArity as __withArity,
|
|
13
|
+
} from "./.lango/runtime.mjs";
|
|
14
|
+
|
|
15
|
+
export class ClaimWatch {
|
|
16
|
+
#driver;
|
|
17
|
+
#queue;
|
|
18
|
+
#job;
|
|
19
|
+
#controller;
|
|
20
|
+
#timer;
|
|
21
|
+
#pending;
|
|
22
|
+
#closed;
|
|
23
|
+
constructor(driver, queue, job) {
|
|
24
|
+
__requireArity(arguments.length, [0, 1, 2], "constructor");
|
|
25
|
+
driver = __boundary(driver);
|
|
26
|
+
queue = __boundary(queue);
|
|
27
|
+
job = __boundary(job);
|
|
28
|
+
this.#driver = driver;
|
|
29
|
+
this.#queue = queue;
|
|
30
|
+
this.#job = job;
|
|
31
|
+
this.#controller = new (__hostGlobal(["AbortController"]))();
|
|
32
|
+
this.#timer = null;
|
|
33
|
+
this.#pending = null;
|
|
34
|
+
this.#closed = false;
|
|
35
|
+
}
|
|
36
|
+
get signal() {
|
|
37
|
+
return __normalize(this.#controller.signal);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
start() {
|
|
41
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#driver) === null) || __requireBoolean(__normalize(this.#closed)))) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
let fire = __bindContexts(() => {
|
|
45
|
+
this.#timer = null;
|
|
46
|
+
this.#pending = this.#check();
|
|
47
|
+
this.#pending = __normalize(this.#pending).catch(__withArity(__bindContexts((error) => {
|
|
48
|
+
const __contextScope = [];
|
|
49
|
+
try {
|
|
50
|
+
error = __boundary(error);
|
|
51
|
+
__normalize(__contextGet("log").err(`[jobId=${__normalize(this.#job.id)}] queue=${__normalize(this.#queue)} Claim check failed: ${error}`));
|
|
52
|
+
return null;
|
|
53
|
+
} finally {
|
|
54
|
+
__contextRestore(__contextScope);
|
|
55
|
+
}
|
|
56
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
57
|
+
this.start();
|
|
58
|
+
return null;
|
|
59
|
+
}));
|
|
60
|
+
return null;
|
|
61
|
+
});
|
|
62
|
+
this.#timer = __hostGlobalCall(["setTimeout"], fire, 1000);
|
|
63
|
+
__normalize(this.#timer.unref());
|
|
64
|
+
return null;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
#check() {
|
|
68
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity(__bindContexts((ignored) => {
|
|
69
|
+
ignored = __boundary(ignored);
|
|
70
|
+
return __normalize(this.#driver.touch(__normalize(this.#queue), [__normalize(this.#job)]));
|
|
71
|
+
return null;
|
|
72
|
+
}), [0], "closure")).then(__withArity(__bindContexts((result) => {
|
|
73
|
+
const __contextScope = [];
|
|
74
|
+
try {
|
|
75
|
+
result = __boundary(result);
|
|
76
|
+
if (__requireBoolean(__requireBoolean(__normalize(result.settled) !== null) && __requireBoolean(!__requireBoolean(__normalize(result.settled.includes(__normalize(this.#job.id))))))) {
|
|
77
|
+
__normalize(__contextGet("log").debug(`[jobId=${__normalize(this.#job.id)}] queue=${__normalize(this.#queue)} Claim ended; aborting local execution`));
|
|
78
|
+
this.#closed = true;
|
|
79
|
+
__normalize(this.#controller.abort());
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
return null;
|
|
83
|
+
} finally {
|
|
84
|
+
__contextRestore(__contextScope);
|
|
85
|
+
}
|
|
86
|
+
}), [0], "closure"));
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
close() {
|
|
90
|
+
this.#closed = true;
|
|
91
|
+
if (__requireBoolean(__normalize(this.#timer) !== null)) {
|
|
92
|
+
__hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
|
|
93
|
+
this.#timer = null;
|
|
94
|
+
}
|
|
95
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(__normalize(this.#pending)));
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=claim_watch.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim_watch.mjs","sources":["claim_watch.lango"],"sourcesContent":["import js global AbortController\nimport js global Promise\nimport js global setTimeout\nimport js global clearTimeout\n\nexport class ClaimWatch(driver, queue, job)\n properties\n signal?\n methods\n start()\n close()\n\nClaimWatch(driver, queue, job)\n @driver = driver\n @queue = queue\n @job = job\n @controller = new AbortController()\n @timer = null\n @pending = null\n @closed = false\n\nClaimWatch:signal?\n return @controller.signal\n\nClaimWatch:start()\n if @driver == null or @closed\n return null\n fire = ()\n @timer = null\n @pending = check()\n @pending = chain @pending\n catch(error)\n context log\n log.err(\"[jobId=${@job.id}] queue=${@queue} Claim check failed: ${error}\")\n finally\n start()\n @timer = setTimeout(fire, 1000)\n @timer.unref()\n return null\n\nClaimWatch:check()\n return chain Promise/resolve(null)\n then(ignored)\n return @driver.touch(@queue, [@job])\n then(result)\n if result.settled != null and !result.settled.includes(@job.id)\n context log\n log.debug(\"[jobId=${@job.id}] queue=${@queue} Claim ended; aborting local execution\")\n @closed = true\n @controller.abort()\n return null\n\nClaimWatch:close()\n @closed = true\n if @timer != null\n clearTimeout(@timer)\n @timer = null\n return Promise/resolve(@pending)\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { loadConfiguration } from "./configuration.mjs";
|
|
3
|
+
import { Worker } from "./worker.mjs";
|
|
4
|
+
import {
|
|
5
|
+
hostGlobal as __hostGlobal,
|
|
6
|
+
hostGlobalCall as __hostGlobalCall,
|
|
7
|
+
println as __println,
|
|
8
|
+
bindContexts as __bindContexts,
|
|
9
|
+
requireBoolean as __requireBoolean,
|
|
10
|
+
normalize as __normalize,
|
|
11
|
+
numericAdd as __numericAdd,
|
|
12
|
+
boundary as __boundary,
|
|
13
|
+
requireArity as __requireArity,
|
|
14
|
+
withArity as __withArity,
|
|
15
|
+
} from "./.lango/runtime.mjs";
|
|
16
|
+
|
|
17
|
+
export function main(args) {
|
|
18
|
+
__requireArity(arguments.length, [0], "main");
|
|
19
|
+
args = __boundary(args);
|
|
20
|
+
let config;
|
|
21
|
+
if (__requireBoolean(__requireBoolean(__normalize(args.length) >= 2) && __requireBoolean(__normalize(args[0]) === "worker"))) {
|
|
22
|
+
return startWorker(args);
|
|
23
|
+
}
|
|
24
|
+
if (__requireBoolean(__requireBoolean(__normalize(args.length) !== 2) || __requireBoolean(__normalize(args[0]) !== "check"))) {
|
|
25
|
+
usage();
|
|
26
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
config = loadConfiguration(__normalize(args[1]));
|
|
31
|
+
__println(`${__normalize(config.application)}: ${config.targets.length} job routes, ${config.schedules.length} schedules; configuration valid`);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss configuration check failed: ${error}\n`));
|
|
34
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function usage() {
|
|
41
|
+
__normalize(__hostGlobal(["process"]).stderr.write("Usage: lango-boss check <application-directory>\n lango-boss worker <application-directory> --identity-module <module> --identity-handler <export> [--workers <count>] [--verbose]\n"));
|
|
42
|
+
return null;
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function startWorker(args) {
|
|
47
|
+
__requireArity(arguments.length, [0], "startWorker");
|
|
48
|
+
args = __boundary(args);
|
|
49
|
+
let settings;
|
|
50
|
+
let worker = null;
|
|
51
|
+
try {
|
|
52
|
+
settings = parseWorker(args);
|
|
53
|
+
worker = new Worker(__normalize(args[1]), settings);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss worker configuration failed: ${error}\n`));
|
|
56
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
let state = { stopping: false, stop: null };
|
|
60
|
+
let stop = __bindContexts(() => {
|
|
61
|
+
if (__requireBoolean(__normalize(state.stopping))) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
state.stopping = true;
|
|
65
|
+
return __normalize(worker.close()).catch(__withArity(__bindContexts((error) => {
|
|
66
|
+
error = __boundary(error);
|
|
67
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss shutdown failed: ${error}\n`));
|
|
68
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
69
|
+
return null;
|
|
70
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
71
|
+
removeSignals(__normalize(state.stop));
|
|
72
|
+
return null;
|
|
73
|
+
}));
|
|
74
|
+
return null;
|
|
75
|
+
});
|
|
76
|
+
state.stop = stop;
|
|
77
|
+
__normalize(__hostGlobal(["process"]).once("SIGINT", stop));
|
|
78
|
+
__normalize(__hostGlobal(["process"]).once("SIGTERM", stop));
|
|
79
|
+
return __normalize(worker.start()).then(__withArity(__bindContexts((ignored) => {
|
|
80
|
+
ignored = __boundary(ignored);
|
|
81
|
+
__println("Lango Boss worker started");
|
|
82
|
+
return null;
|
|
83
|
+
return null;
|
|
84
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
85
|
+
error = __boundary(error);
|
|
86
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss worker startup failed: ${error}\n`));
|
|
87
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
88
|
+
removeSignals(__normalize(state.stop));
|
|
89
|
+
return null;
|
|
90
|
+
return null;
|
|
91
|
+
}), [0], "closure"));
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function removeSignals(handler) {
|
|
96
|
+
__requireArity(arguments.length, [0], "removeSignals");
|
|
97
|
+
handler = __boundary(handler);
|
|
98
|
+
__normalize(__hostGlobal(["process"]).removeListener("SIGINT", handler));
|
|
99
|
+
__normalize(__hostGlobal(["process"]).removeListener("SIGTERM", handler));
|
|
100
|
+
return null;
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseWorker(args) {
|
|
105
|
+
__requireArity(arguments.length, [0], "parseWorker");
|
|
106
|
+
args = __boundary(args);
|
|
107
|
+
let settings = { identity: { } };
|
|
108
|
+
let index = 2;
|
|
109
|
+
let seen = [];
|
|
110
|
+
__loop1: while (__requireBoolean(index < __normalize(args.length))) {
|
|
111
|
+
let flag = __normalize(args[index]);
|
|
112
|
+
if (__requireBoolean(__normalize(seen.includes(flag)))) {
|
|
113
|
+
throw `Duplicate worker option: ${flag}`;
|
|
114
|
+
}
|
|
115
|
+
seen.push(flag);
|
|
116
|
+
if (__requireBoolean(flag === "--verbose")) {
|
|
117
|
+
__hostGlobal(["process"]).env.LANGO_VERBOSE = "1";
|
|
118
|
+
index = __numericAdd(index, 1);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
index = __numericAdd(index, 1);
|
|
122
|
+
if (__requireBoolean(index >= __normalize(args.length))) {
|
|
123
|
+
throw `Missing value for ${flag}`;
|
|
124
|
+
}
|
|
125
|
+
let value = __normalize(args[index]);
|
|
126
|
+
if (flag === "--identity-module") {
|
|
127
|
+
settings.identity.module = value;
|
|
128
|
+
} else if (flag === "--identity-handler") {
|
|
129
|
+
settings.identity.handler = value;
|
|
130
|
+
} else if (flag === "--workers") {
|
|
131
|
+
settings.workers = __hostGlobalCall(["Number"], value);
|
|
132
|
+
} else {
|
|
133
|
+
throw `Unknown worker option: ${flag}`;
|
|
134
|
+
}
|
|
135
|
+
index = __numericAdd(index, 1);
|
|
136
|
+
}
|
|
137
|
+
return settings;
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const { configure } = await import("./.lango/runtime.mjs");
|
|
141
|
+
configure({ output: (value) => console.log(value) });
|
|
142
|
+
await main(process.argv.slice(2));
|
|
143
|
+
//# sourceMappingURL=cli.mjs.map
|
package/dist/cli.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","sources":["cli.lango"],"sourcesContent":["import \"./configuration\"\n loadConfiguration(directory)\nimport \"./worker\"\n class Worker\nimport js global process\nimport js global Number\n\nexport main(args)\n\nmain(args)\n if args.length >= 2 and args[0] == \"worker\"\n return startWorker(args)\n if args.length != 2 or args[0] != \"check\"\n usage()\n process.exitCode = 1\n return null\n try\n config = loadConfiguration(args[1])\n println(\"${config.application}: ${config.targets.length} job routes, ${config.schedules.length} schedules; configuration valid\")\n catch error\n process.stderr.write(\"Lango Boss configuration check failed: ${error}\\n\")\n process.exitCode = 1\n return null\n\nusage()\n process.stderr.write(\"Usage: lango-boss check <application-directory>\\n lango-boss worker <application-directory> --identity-module <module> --identity-handler <export> [--workers <count>] [--verbose]\\n\")\n return null\n\nstartWorker(args)\n worker = null\n try\n settings = parseWorker(args)\n worker = new Worker(args[1], settings)\n catch error\n process.stderr.write(\"Lango Boss worker configuration failed: ${error}\\n\")\n process.exitCode = 1\n return null\n state = {\n stopping: false\n stop: null\n }\n stop = ()\n capture worker\n capture state\n if state.stopping\n return null\n state.stopping = true\n return chain worker.close()\n catch(error)\n process.stderr.write(\"Lango Boss shutdown failed: ${error}\\n\")\n process.exitCode = 1\n finally\n capture state\n removeSignals(state.stop)\n state.stop = stop\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n return chain worker.start()\n then(ignored)\n println(\"Lango Boss worker started\")\n return null\n catch(error)\n capture state\n process.stderr.write(\"Lango Boss worker startup failed: ${error}\\n\")\n process.exitCode = 1\n removeSignals(state.stop)\n return null\n\nremoveSignals(handler)\n process.removeListener(\"SIGINT\", handler)\n process.removeListener(\"SIGTERM\", handler)\n return null\n\nparseWorker(args)\n settings = {\n identity: {}\n }\n index = 2\n seen = []\n loop while index < args.length\n flag = args[index]\n if seen.includes(flag)\n throw \"Duplicate worker option: ${flag}\"\n seen.add(flag)\n if flag == \"--verbose\"\n process.env.LANGO_VERBOSE = \"1\"\n index = index + 1\n continue\n index = index + 1\n if index >= args.length\n throw \"Missing value for ${flag}\"\n value = args[index]\n switch flag\n case \"--identity-module\"\n settings.identity.module = value\n case \"--identity-handler\"\n settings.identity.handler = value\n case \"--workers\"\n settings.workers = Number(value)\n else\n throw \"Unknown worker option: ${flag}\"\n index = index + 1\n return settings\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { scheduleConfiguration } from "./schedules.mjs";
|
|
2
|
+
import { name } from "./validation.mjs";
|
|
3
|
+
import * as server from "@lango-project/lango-server";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
fromJson as __fromJson,
|
|
8
|
+
toJson as __toJson,
|
|
9
|
+
isNumber as __isNumber,
|
|
10
|
+
isString as __isString,
|
|
11
|
+
isBool as __isBool,
|
|
12
|
+
isObject as __isObject,
|
|
13
|
+
isArray as __isArray,
|
|
14
|
+
requireBoolean as __requireBoolean,
|
|
15
|
+
normalize as __normalize,
|
|
16
|
+
boundary as __boundary,
|
|
17
|
+
requireArity as __requireArity,
|
|
18
|
+
} from "./.lango/runtime.mjs";
|
|
19
|
+
|
|
20
|
+
export function loadConfiguration(directory) {
|
|
21
|
+
__requireArity(arguments.length, [0], "loadConfiguration");
|
|
22
|
+
directory = __boundary(directory);
|
|
23
|
+
let xml;
|
|
24
|
+
let parsed;
|
|
25
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(directory))) || __requireBoolean(__normalize(directory.trim()) === ""))) {
|
|
26
|
+
throw "Application directory is required";
|
|
27
|
+
}
|
|
28
|
+
if (__requireBoolean(__requireBoolean(__normalize(server.readDatabaseConfiguration) === null) || __requireBoolean(__normalize(server.readJobRoutes) === null))) {
|
|
29
|
+
throw "Lango Server must provide readDatabaseConfiguration and readJobRoutes; update or link the current Server package";
|
|
30
|
+
}
|
|
31
|
+
let root = __normalize(path.resolve(directory));
|
|
32
|
+
let application = __fromJson(__normalize(fs.readFileSync(__normalize(path.join(root, "package.json")), "utf8")));
|
|
33
|
+
let appName = name(__normalize(application.name), "Application name");
|
|
34
|
+
let database = __normalize(server.readDatabaseConfiguration(root));
|
|
35
|
+
if (__requireBoolean(__requireBoolean(database === null) || __requireBoolean(__normalize(database.type) !== "postgresql"))) {
|
|
36
|
+
throw "Lango Boss requires the application's PostgreSQL database configuration";
|
|
37
|
+
}
|
|
38
|
+
let targets = __normalize(server.readJobRoutes(root));
|
|
39
|
+
for (const target of targets) {
|
|
40
|
+
name(__normalize(target.queue), "Queue name");
|
|
41
|
+
}
|
|
42
|
+
let schedules = [];
|
|
43
|
+
let revision = 0;
|
|
44
|
+
let file = __normalize(path.join(root, "jobs.xml"));
|
|
45
|
+
try {
|
|
46
|
+
xml = __normalize(fs.readFileSync(file, "utf8"));
|
|
47
|
+
parsed = scheduleConfiguration(xml, targets);
|
|
48
|
+
schedules = __normalize(parsed.items);
|
|
49
|
+
revision = __normalize(parsed.revision);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (__requireBoolean(__normalize(error.code) !== "ENOENT")) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { application: appName, root: root, database: database, targets: targets, schedules: schedules, scheduleRevision: revision };
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=configuration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.mjs","sources":["configuration.lango"],"sourcesContent":["import js \"@lango-project/lango-server\" as server\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport \"./schedules\"\n scheduleConfiguration(xml, targets)\nimport \"./validation\"\n name(value, label)\n\nexport loadConfiguration(directory)\n\nloadConfiguration(directory)\n if !is_string(directory) or directory.trim() == \"\"\n throw \"Application directory is required\"\n if server.readDatabaseConfiguration == null or server.readJobRoutes == null\n throw \"Lango Server must provide readDatabaseConfiguration and readJobRoutes; update or link the current Server package\"\n root = path/resolve(directory)\n application = from_json(fs/readFileSync(path/join(root, \"package.json\"), \"utf8\"))\n appName = name(application.name, \"Application name\")\n database = server/readDatabaseConfiguration(root)\n if database == null or database.type != \"postgresql\"\n throw \"Lango Boss requires the application's PostgreSQL database configuration\"\n targets = server/readJobRoutes(root)\n for targets as target\n name(target.queue, \"Queue name\")\n schedules = []\n revision = 0\n file = path/join(root, \"jobs.xml\")\n try\n xml = fs/readFileSync(file, \"utf8\")\n parsed = scheduleConfiguration(xml, targets)\n schedules = parsed.items\n revision = parsed.revision\n catch error\n if error.code != \"ENOENT\"\n throw error\n return {\n application: appName\n root: root\n database: database\n targets: targets\n schedules: schedules\n scheduleRevision: revision\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { executionTask } from "./envelope.mjs";
|
|
2
|
+
import { ClaimWatch } from "./claim_watch.mjs";
|
|
3
|
+
import {
|
|
4
|
+
hostGlobal as __hostGlobal,
|
|
5
|
+
contextGet as __contextGet,
|
|
6
|
+
contextSet as __contextSet,
|
|
7
|
+
contextRestore as __contextRestore,
|
|
8
|
+
bindContexts as __bindContexts,
|
|
9
|
+
isNumber as __isNumber,
|
|
10
|
+
isString as __isString,
|
|
11
|
+
isBool as __isBool,
|
|
12
|
+
isObject as __isObject,
|
|
13
|
+
isArray as __isArray,
|
|
14
|
+
requireBoolean as __requireBoolean,
|
|
15
|
+
normalize as __normalize,
|
|
16
|
+
finite as __finite,
|
|
17
|
+
boundary as __boundary,
|
|
18
|
+
requireArity as __requireArity,
|
|
19
|
+
withArity as __withArity,
|
|
20
|
+
} from "./.lango/runtime.mjs";
|
|
21
|
+
|
|
22
|
+
export class Dispatcher {
|
|
23
|
+
#config;
|
|
24
|
+
#executor;
|
|
25
|
+
constructor(config, executor) {
|
|
26
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
27
|
+
config = __boundary(config);
|
|
28
|
+
executor = __boundary(executor);
|
|
29
|
+
this.#config = config;
|
|
30
|
+
this.#executor = executor;
|
|
31
|
+
}
|
|
32
|
+
run(queue, jobs, driver = null) {
|
|
33
|
+
const __contextScope = [];
|
|
34
|
+
try {
|
|
35
|
+
__requireArity(arguments.length, [0, 1], "run");
|
|
36
|
+
queue = __boundary(queue);
|
|
37
|
+
jobs = __boundary(jobs);
|
|
38
|
+
driver = __boundary(driver);
|
|
39
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isArray(jobs))) || __requireBoolean(__normalize(jobs.length) !== 1))) {
|
|
40
|
+
return __normalize(__hostGlobal(["Promise"]).reject("Dispatcher requires a single claimed job"));
|
|
41
|
+
}
|
|
42
|
+
let job = __normalize(jobs[0]);
|
|
43
|
+
let task = null;
|
|
44
|
+
try {
|
|
45
|
+
task = executionTask(__normalize(this.#config), queue, job);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
__normalize(__contextGet("log").err(`[jobId=${__normalize(job.id)}] queue=${queue} Invalid job envelope: ${error}`));
|
|
48
|
+
return __normalize(__hostGlobal(["Promise"]).resolve([outcome(__normalize(job.id), "deadletter", { version: 1, error: { code: "InvalidJobEnvelope", permanent: true } })]));
|
|
49
|
+
}
|
|
50
|
+
__normalize(__contextGet("log").debug(`[jobId=${__normalize(job.id)}] queue=${queue} path=${__normalize(task.path)} dispatching attempt=${__normalize(task.attempt)}`));
|
|
51
|
+
let watch = new ClaimWatch(driver, queue, job);
|
|
52
|
+
__normalize(watch.start());
|
|
53
|
+
let signal = __normalize(watch.signal);
|
|
54
|
+
if (__requireBoolean(__normalize(job.signal) !== null)) {
|
|
55
|
+
signal = __normalize(__hostGlobal(["AbortSignal"]).any([signal, __normalize(job.signal)]));
|
|
56
|
+
}
|
|
57
|
+
return __normalize(this.#executor.execute(task, { signal: signal, timeoutMs: __finite(__normalize(job.expireInSeconds) * 1000) })).then(__withArity(__bindContexts((value) => {
|
|
58
|
+
const __contextScope = [];
|
|
59
|
+
try {
|
|
60
|
+
value = __boundary(value);
|
|
61
|
+
__normalize(__contextGet("log").debug(`[jobId=${__normalize(job.id)}] execution completed; settling claimed attempt`));
|
|
62
|
+
return [outcome(__normalize(job.id), "completed", { version: 1, value: value })];
|
|
63
|
+
return null;
|
|
64
|
+
} finally {
|
|
65
|
+
__contextRestore(__contextScope);
|
|
66
|
+
}
|
|
67
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
68
|
+
const __contextScope = [];
|
|
69
|
+
try {
|
|
70
|
+
error = __boundary(error);
|
|
71
|
+
let permanent = __normalize(error.permanent) === true;
|
|
72
|
+
let state = "failed";
|
|
73
|
+
if (__requireBoolean(permanent)) {
|
|
74
|
+
state = "deadletter";
|
|
75
|
+
}
|
|
76
|
+
let code = __normalize(error.code);
|
|
77
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(code))) || __requireBoolean(code === ""))) {
|
|
78
|
+
code = "ExecutionFailed";
|
|
79
|
+
}
|
|
80
|
+
return [outcome(__normalize(job.id), state, { version: 1, error: { code: code, permanent: permanent } })];
|
|
81
|
+
return null;
|
|
82
|
+
} finally {
|
|
83
|
+
__contextRestore(__contextScope);
|
|
84
|
+
}
|
|
85
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
86
|
+
const __contextScope = [];
|
|
87
|
+
try {
|
|
88
|
+
return __normalize(watch.close());
|
|
89
|
+
return null;
|
|
90
|
+
} finally {
|
|
91
|
+
__contextRestore(__contextScope);
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
return null;
|
|
95
|
+
} finally {
|
|
96
|
+
__contextRestore(__contextScope);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function outcome(id, state, output) {
|
|
101
|
+
__requireArity(arguments.length, [0, 1, 2], "outcome");
|
|
102
|
+
id = __boundary(id);
|
|
103
|
+
state = __boundary(state);
|
|
104
|
+
output = __boundary(output);
|
|
105
|
+
return { id: id, status: state, output: output };
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=dispatcher.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.mjs","sources":["dispatcher.lango"],"sourcesContent":["import \"./envelope\"\n executionTask(config, queue, job)\nimport js global Promise\nimport js global AbortSignal\nimport \"./claim_watch\"\n class ClaimWatch\n\nexport class Dispatcher(config, executor)\n methods\n run(queue, jobs, driver = null)\n\nDispatcher(config, executor)\n @config = config\n @executor = executor\n\nDispatcher:run(queue, jobs, driver = null)\n context log\n if !is_array(jobs) or jobs.length != 1\n return Promise/reject(\"Dispatcher requires a single claimed job\")\n job = jobs[0]\n task = null\n try\n task = executionTask(@config, queue, job)\n catch error\n log.err(\"[jobId=${job.id}] queue=${queue} Invalid job envelope: ${error}\")\n return Promise/resolve([outcome(job.id, \"deadletter\", {\n version: 1\n error: {\n code: \"InvalidJobEnvelope\"\n permanent: true\n }\n })])\n log.debug(\"[jobId=${job.id}] queue=${queue} path=${task.path} dispatching attempt=${task.attempt}\")\n watch = new ClaimWatch(driver, queue, job)\n watch.start()\n signal = watch.signal?\n if job.signal != null\n signal = AbortSignal/any([signal, job.signal])\n return chain @executor.execute(task, {\n signal: signal\n timeoutMs: job.expireInSeconds * 1000\n })\n then(value)\n capture job\n log.debug(\"[jobId=${job.id}] execution completed; settling claimed attempt\")\n return [outcome(job.id, \"completed\", {\n version: 1\n value: value\n })]\n catch(error)\n capture job\n permanent = error.permanent == true\n state = \"failed\"\n if permanent\n state = \"deadletter\"\n code = error.code\n if !is_string(code) or code == \"\"\n code = \"ExecutionFailed\"\n return [outcome(job.id, state, {\n version: 1\n error: {\n code: code\n permanent: permanent\n }\n })]\n finally\n capture watch\n return watch.close()\n\noutcome(id, state, output)\n return {\n id: id\n status: state\n output: output\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA;;;;;;;;;"}
|