@lango-project/lango-boss 0.0.0-stage → 0.1.1
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 +118 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/entries/cli.mjs +139 -0
- package/dist/.lango/entries/cli.mjs.map +1 -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 +7 -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/entries/app.mjs +133 -0
- package/examples/reports/dist/.lango/entries/app.mjs.map +1 -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 +7 -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 +62 -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,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostGlobal as __hostGlobal,
|
|
3
|
+
hostGlobalCall as __hostGlobalCall,
|
|
4
|
+
isNumber as __isNumber,
|
|
5
|
+
isString as __isString,
|
|
6
|
+
isBool as __isBool,
|
|
7
|
+
isObject as __isObject,
|
|
8
|
+
isArray as __isArray,
|
|
9
|
+
entries as __entries,
|
|
10
|
+
requireBoolean as __requireBoolean,
|
|
11
|
+
normalize as __normalize,
|
|
12
|
+
boundary as __boundary,
|
|
13
|
+
requireArity as __requireArity,
|
|
14
|
+
} from "./.lango/runtime.mjs";
|
|
15
|
+
|
|
16
|
+
export function attributes(tag, allowed) {
|
|
17
|
+
__requireArity(arguments.length, [0, 1], "attributes");
|
|
18
|
+
tag = __boundary(tag);
|
|
19
|
+
allowed = __boundary(allowed);
|
|
20
|
+
for (const [key, value] of __entries(__normalize(tag.attributes()))) {
|
|
21
|
+
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
22
|
+
throw `Unknown ${__normalize(tag.tag())} attribute: ${key}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function empty(tag) {
|
|
30
|
+
__requireArity(arguments.length, [0], "empty");
|
|
31
|
+
tag = __boundary(tag);
|
|
32
|
+
if (__requireBoolean(__requireBoolean(__normalize(__normalize(tag.children()).length) !== 0) || __requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== ""))) {
|
|
33
|
+
throw `Expected an empty ${__normalize(tag.tag())} element`;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function integer(value, fallback, minimum, maximum, name) {
|
|
40
|
+
__requireArity(arguments.length, [0, 1, 2, 3, 4], "integer");
|
|
41
|
+
value = __boundary(value);
|
|
42
|
+
fallback = __boundary(fallback);
|
|
43
|
+
minimum = __boundary(minimum);
|
|
44
|
+
maximum = __boundary(maximum);
|
|
45
|
+
name = __boundary(name);
|
|
46
|
+
if (__requireBoolean(value === null)) {
|
|
47
|
+
return fallback;
|
|
48
|
+
}
|
|
49
|
+
let pattern = new (__hostGlobal(["RegExp"]))("^[0-9]+$");
|
|
50
|
+
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(value)))))) {
|
|
51
|
+
throw `${name} must be an integer`;
|
|
52
|
+
}
|
|
53
|
+
let result = __hostGlobalCall(["Number"], value);
|
|
54
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(result)))) || __requireBoolean(result < minimum)) || __requireBoolean(result > maximum))) {
|
|
55
|
+
throw `${name} must be between ${minimum} and ${maximum}`;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function boolean(value, fallback, name) {
|
|
62
|
+
__requireArity(arguments.length, [0, 1, 2], "boolean");
|
|
63
|
+
value = __boundary(value);
|
|
64
|
+
fallback = __boundary(fallback);
|
|
65
|
+
name = __boundary(name);
|
|
66
|
+
if (__requireBoolean(value === null)) {
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
if (__requireBoolean(__requireBoolean(value !== "true") && __requireBoolean(value !== "false"))) {
|
|
70
|
+
throw `${name} must be true or false`;
|
|
71
|
+
}
|
|
72
|
+
return value === "true";
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function name(value, label) {
|
|
77
|
+
__requireArity(arguments.length, [0, 1], "name");
|
|
78
|
+
value = __boundary(value);
|
|
79
|
+
label = __boundary(label);
|
|
80
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(__normalize(value.trim()) !== value)) || __requireBoolean(value === "")) || __requireBoolean(__normalize(value.length) > 200))) {
|
|
81
|
+
throw `${label} must be a nonempty name of at most 200 characters`;
|
|
82
|
+
}
|
|
83
|
+
let pattern = new (__hostGlobal(["RegExp"]))("[\\x00-\\x1f\\x7f]");
|
|
84
|
+
if (__requireBoolean(__normalize(pattern.test(value)))) {
|
|
85
|
+
throw `${label} cannot contain control characters`;
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.mjs","sources":["validation.lango"],"sourcesContent":["import js global Number\nimport js global RegExp\n\nexport attributes(tag, allowed)\nexport empty(tag)\nexport integer(value, fallback, minimum, maximum, name)\nexport boolean(value, fallback, name)\nexport name(value, label)\n\nattributes(tag, allowed)\n for tag.attributes() as key: value\n if !allowed.includes(key)\n throw \"Unknown ${tag.tag()} attribute: ${key}\"\n return null\n\nempty(tag)\n if tag.children().length != 0 or tag.innerText().trim() != \"\"\n throw \"Expected an empty ${tag.tag()} element\"\n return null\n\ninteger(value, fallback, minimum, maximum, name)\n if value == null\n return fallback\n pattern = new RegExp(\"^[0-9]+$\")\n if !is_string(value) or !pattern.test(value)\n throw \"${name} must be an integer\"\n result = Number(value)\n if !Number/isSafeInteger(result) or result < minimum or result > maximum\n throw \"${name} must be between ${minimum} and ${maximum}\"\n return result\n\nboolean(value, fallback, name)\n if value == null\n return fallback\n if value != \"true\" and value != \"false\"\n throw \"${name} must be true or false\"\n return value == \"true\"\n\nname(value, label)\n if !is_string(value) or value.trim() != value or value == \"\" or value.length > 200\n throw \"${label} must be a nonempty name of at most 200 characters\"\n pattern = new RegExp(\"[\\\\x00-\\\\x1f\\\\x7f]\")\n if pattern.test(value)\n throw \"${label} cannot contain control characters\"\n return value\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;AAMA;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"f4765fb2a6daaadc09359e912d536250ce3cb654fb55d0f231d73ca4a5098b99","outputHash":"27f4ad3f25b39f6e88eae2997d7634fec7e4bdd9b7f5009936d7ef2907709805","mapHash":"2d54ad1756f389327399334e05cd07b858b9f8adc16d1f2a7c57faf63796526e"}}
|
package/dist/worker.mjs
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { loadConfiguration } from "./configuration.mjs";
|
|
2
|
+
import { createDriver, prepareQueues, queueProvider } from "./driver.mjs";
|
|
3
|
+
import { Dispatcher } from "./dispatcher.mjs";
|
|
4
|
+
import { synchronizeSchedules } from "./schedule_sync.mjs";
|
|
5
|
+
import { Retention } from "./retention.mjs";
|
|
6
|
+
import { prepareManagement } from "./management.mjs";
|
|
7
|
+
import * as crypto from "node:crypto";
|
|
8
|
+
import * as server from "@lango-project/lango-server";
|
|
9
|
+
import {
|
|
10
|
+
hostGlobal as __hostGlobal,
|
|
11
|
+
bindContexts as __bindContexts,
|
|
12
|
+
fromJson as __fromJson,
|
|
13
|
+
toJson as __toJson,
|
|
14
|
+
isNumber as __isNumber,
|
|
15
|
+
isString as __isString,
|
|
16
|
+
isBool as __isBool,
|
|
17
|
+
isObject as __isObject,
|
|
18
|
+
isArray as __isArray,
|
|
19
|
+
entries as __entries,
|
|
20
|
+
requireBoolean as __requireBoolean,
|
|
21
|
+
normalize as __normalize,
|
|
22
|
+
finite as __finite,
|
|
23
|
+
boundary as __boundary,
|
|
24
|
+
requireArity as __requireArity,
|
|
25
|
+
withArity as __withArity,
|
|
26
|
+
} from "./.lango/runtime.mjs";
|
|
27
|
+
|
|
28
|
+
export class Worker {
|
|
29
|
+
#config;
|
|
30
|
+
#settings;
|
|
31
|
+
#queues;
|
|
32
|
+
#executor;
|
|
33
|
+
#dispatcher;
|
|
34
|
+
#state;
|
|
35
|
+
#driver;
|
|
36
|
+
#starting;
|
|
37
|
+
#closing;
|
|
38
|
+
#releasing;
|
|
39
|
+
#closeError;
|
|
40
|
+
#retention;
|
|
41
|
+
constructor(directory, settings) {
|
|
42
|
+
__requireArity(arguments.length, [0, 1], "constructor");
|
|
43
|
+
directory = __boundary(directory);
|
|
44
|
+
settings = __boundary(settings);
|
|
45
|
+
this.#config = loadConfiguration(directory);
|
|
46
|
+
this.#settings = workerSettings(settings);
|
|
47
|
+
this.#queues = [];
|
|
48
|
+
for (const target of __normalize(this.#config.targets)) {
|
|
49
|
+
if (__requireBoolean(!__requireBoolean(__normalize(this.#queues.includes(__normalize(target.queue)))))) {
|
|
50
|
+
this.#queues.push(__normalize(target.queue));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
this.#executor = new server.Executor(__normalize(this.#config.root), { identity: __normalize(this.#settings.identity), workers: __normalize(this.#settings.workers), maxQueue: __finite(__normalize(this.#queues.length) * __normalize(this.#settings.workers)), startupTimeoutMs: __normalize(this.#settings.startupTimeoutMs), shutdownTimeoutMs: __normalize(this.#settings.shutdownTimeoutMs), queueProvider: queueProvider(__normalize(this.#config)) });
|
|
54
|
+
this.#dispatcher = new Dispatcher(__normalize(this.#config), __normalize(this.#executor));
|
|
55
|
+
this.#state = "new";
|
|
56
|
+
this.#driver = null;
|
|
57
|
+
this.#starting = null;
|
|
58
|
+
this.#closing = null;
|
|
59
|
+
this.#releasing = null;
|
|
60
|
+
this.#closeError = null;
|
|
61
|
+
this.#retention = new Retention(__normalize(this.#config), __normalize(this.#settings.cleanupIntervalSeconds), __normalize(this.#settings.cleanupBatchSize));
|
|
62
|
+
}
|
|
63
|
+
start() {
|
|
64
|
+
if (__requireBoolean(__normalize(this.#state) !== "new")) {
|
|
65
|
+
return __normalize(__hostGlobal(["Promise"]).reject("Worker can only be started once"));
|
|
66
|
+
}
|
|
67
|
+
this.#state = "starting";
|
|
68
|
+
this.#driver = createDriver(__normalize(this.#config));
|
|
69
|
+
this.#starting = this.#launch();
|
|
70
|
+
return __normalize(this.#starting);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
#launch() {
|
|
74
|
+
return __normalize(this.#driver.start()).then(__withArity(__bindContexts((ignored) => {
|
|
75
|
+
ignored = __boundary(ignored);
|
|
76
|
+
return prepareQueues(__normalize(this.#driver), __normalize(this.#config.targets));
|
|
77
|
+
return null;
|
|
78
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
79
|
+
ignored = __boundary(ignored);
|
|
80
|
+
return prepareManagement(__normalize(this.#config));
|
|
81
|
+
return null;
|
|
82
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
83
|
+
ignored = __boundary(ignored);
|
|
84
|
+
return __normalize(this.#executor.start());
|
|
85
|
+
return null;
|
|
86
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
87
|
+
ignored = __boundary(ignored);
|
|
88
|
+
return this.#validateSchedules();
|
|
89
|
+
return null;
|
|
90
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
91
|
+
ignored = __boundary(ignored);
|
|
92
|
+
return synchronizeSchedules(__normalize(this.#config));
|
|
93
|
+
return null;
|
|
94
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
95
|
+
ignored = __boundary(ignored);
|
|
96
|
+
return __normalize(this.#retention.start());
|
|
97
|
+
return null;
|
|
98
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
99
|
+
ignored = __boundary(ignored);
|
|
100
|
+
return this.#activateConsumer();
|
|
101
|
+
return null;
|
|
102
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
103
|
+
ignored = __boundary(ignored);
|
|
104
|
+
let pending = __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
105
|
+
for (const queue of __normalize(this.#queues)) {
|
|
106
|
+
pending = this.#subscribe(pending, queue);
|
|
107
|
+
}
|
|
108
|
+
return pending;
|
|
109
|
+
return null;
|
|
110
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
111
|
+
ignored = __boundary(ignored);
|
|
112
|
+
if (__requireBoolean(__normalize(this.#state) !== "starting")) {
|
|
113
|
+
throw "Worker closed during startup";
|
|
114
|
+
}
|
|
115
|
+
this.#state = "running";
|
|
116
|
+
return null;
|
|
117
|
+
return null;
|
|
118
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
119
|
+
error = __boundary(error);
|
|
120
|
+
this.#state = "closing";
|
|
121
|
+
return this.#release().finally(__bindContexts(() => {
|
|
122
|
+
throw error;
|
|
123
|
+
return null;
|
|
124
|
+
}));
|
|
125
|
+
return null;
|
|
126
|
+
}), [0], "closure"));
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
#validateSchedules() {
|
|
130
|
+
let pending = __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
131
|
+
let checked = __normalize(__hostGlobal(["Object"]).create(null));
|
|
132
|
+
for (const item of __normalize(this.#config.schedules)) {
|
|
133
|
+
let key = __toJson([__normalize(item.identity), __normalize(item.path)]);
|
|
134
|
+
if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(checked, key))))) {
|
|
135
|
+
checked[key] = true;
|
|
136
|
+
pending = this.#validateSchedule(pending, item);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return pending;
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
#validateSchedule(pending, item) {
|
|
143
|
+
__requireArity(arguments.length, [0, 1], "validateSchedule");
|
|
144
|
+
pending = __boundary(pending);
|
|
145
|
+
item = __boundary(item);
|
|
146
|
+
return pending.then(__withArity(__bindContexts((ignored) => {
|
|
147
|
+
ignored = __boundary(ignored);
|
|
148
|
+
return __normalize(this.#executor.authorize({ id: `schedule-check:${__normalize(crypto.randomUUID())}`, path: __normalize(item.path), input: { }, source: { kind: "system", identity: __normalize(item.identity) } }));
|
|
149
|
+
return null;
|
|
150
|
+
}), [0], "closure"));
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
#activateConsumer() {
|
|
154
|
+
return __normalize(this.#driver.stop()).then(__withArity(__bindContexts((ignored) => {
|
|
155
|
+
ignored = __boundary(ignored);
|
|
156
|
+
if (__requireBoolean(__normalize(this.#state) !== "starting")) {
|
|
157
|
+
throw "Worker closed before consumer activation";
|
|
158
|
+
}
|
|
159
|
+
this.#driver = createDriver(__normalize(this.#config), true, __normalize(this.#config.scheduleRevision) > 0, __normalize(this.#settings.cronMonitorIntervalSeconds));
|
|
160
|
+
return __normalize(this.#driver.start());
|
|
161
|
+
return null;
|
|
162
|
+
}), [0], "closure"));
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
#subscribe(pending, queue) {
|
|
166
|
+
__requireArity(arguments.length, [0, 1], "subscribe");
|
|
167
|
+
pending = __boundary(pending);
|
|
168
|
+
queue = __boundary(queue);
|
|
169
|
+
return pending.then(__withArity(__bindContexts((ignored) => {
|
|
170
|
+
ignored = __boundary(ignored);
|
|
171
|
+
if (__requireBoolean(__normalize(this.#state) !== "starting")) {
|
|
172
|
+
throw "Worker closed during startup";
|
|
173
|
+
}
|
|
174
|
+
let handler = __withArity(__bindContexts((jobs) => {
|
|
175
|
+
jobs = __boundary(jobs);
|
|
176
|
+
return __normalize(this.#dispatcher.run(queue, jobs, __normalize(this.#driver)));
|
|
177
|
+
return null;
|
|
178
|
+
}), [0], "closure");
|
|
179
|
+
return __normalize(this.#driver.work(queue, { includeMetadata: true, perJobResults: true, batchSize: 1, localConcurrency: __normalize(this.#settings.workers), pollingIntervalSeconds: __normalize(this.#settings.pollingIntervalSeconds), heartbeatRefreshSeconds: __normalize(this.#settings.heartbeatRefreshSeconds) }, handler));
|
|
180
|
+
return null;
|
|
181
|
+
}), [0], "closure"));
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
close() {
|
|
185
|
+
if (__requireBoolean(__normalize(this.#closing) !== null)) {
|
|
186
|
+
return __normalize(this.#closing);
|
|
187
|
+
}
|
|
188
|
+
if (__requireBoolean(__requireBoolean(__normalize(this.#state) === "new") || __requireBoolean(__normalize(this.#state) === "closed"))) {
|
|
189
|
+
this.#state = "closed";
|
|
190
|
+
return __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
191
|
+
}
|
|
192
|
+
this.#state = "closing";
|
|
193
|
+
let pending = __normalize(__hostGlobal(["Promise"]).resolve(null));
|
|
194
|
+
if (__requireBoolean(__normalize(this.#starting) !== null)) {
|
|
195
|
+
pending = __normalize(this.#starting);
|
|
196
|
+
}
|
|
197
|
+
this.#closing = this.#closeAfter(pending);
|
|
198
|
+
return __normalize(this.#closing);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
#closeAfter(pending) {
|
|
202
|
+
__requireArity(arguments.length, [0], "closeAfter");
|
|
203
|
+
pending = __boundary(pending);
|
|
204
|
+
return pending.catch(__withArity(__bindContexts((error) => {
|
|
205
|
+
error = __boundary(error);
|
|
206
|
+
return null;
|
|
207
|
+
return null;
|
|
208
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
209
|
+
ignored = __boundary(ignored);
|
|
210
|
+
return this.#release();
|
|
211
|
+
return null;
|
|
212
|
+
}), [0], "closure"));
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
#release() {
|
|
216
|
+
if (__requireBoolean(__normalize(this.#releasing) === null)) {
|
|
217
|
+
this.#releasing = this.#shutdown();
|
|
218
|
+
}
|
|
219
|
+
return __normalize(this.#releasing);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
#shutdown() {
|
|
223
|
+
let stops = [];
|
|
224
|
+
if (__requireBoolean(__normalize(this.#driver) !== null)) {
|
|
225
|
+
for (const queue of __normalize(this.#queues)) {
|
|
226
|
+
stops.push(__normalize(this.#driver.offWork(queue, { wait: false })));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return __normalize(__hostGlobal(["Promise"]).all(stops)).finally(__bindContexts(() => {
|
|
230
|
+
return __normalize(this.#retention.close());
|
|
231
|
+
return null;
|
|
232
|
+
})).catch(__withArity(__bindContexts((error) => {
|
|
233
|
+
error = __boundary(error);
|
|
234
|
+
this.#closeError = error;
|
|
235
|
+
return null;
|
|
236
|
+
return null;
|
|
237
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
238
|
+
ignored = __boundary(ignored);
|
|
239
|
+
return __normalize(this.#executor.close());
|
|
240
|
+
return null;
|
|
241
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
242
|
+
error = __boundary(error);
|
|
243
|
+
this.#closeError = error;
|
|
244
|
+
return null;
|
|
245
|
+
return null;
|
|
246
|
+
}), [0], "closure")).then(__withArity(__bindContexts((ignored) => {
|
|
247
|
+
ignored = __boundary(ignored);
|
|
248
|
+
if (__requireBoolean(__normalize(this.#driver) !== null)) {
|
|
249
|
+
return __normalize(this.#driver.stop({ graceful: true, timeout: __normalize(this.#settings.shutdownTimeoutMs) }));
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
return null;
|
|
253
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
254
|
+
this.#state = "closed";
|
|
255
|
+
return null;
|
|
256
|
+
})).then(__withArity(__bindContexts((ignored) => {
|
|
257
|
+
ignored = __boundary(ignored);
|
|
258
|
+
if (__requireBoolean(__normalize(this.#closeError) !== null)) {
|
|
259
|
+
throw __normalize(this.#closeError);
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
return null;
|
|
263
|
+
}), [0], "closure"));
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function workerSettings(settings) {
|
|
268
|
+
__requireArity(arguments.length, [0], "workerSettings");
|
|
269
|
+
settings = __boundary(settings);
|
|
270
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(settings === null) || __requireBoolean(!__requireBoolean(__isObject(settings)))) || __requireBoolean(__isArray(settings)))) {
|
|
271
|
+
throw "Worker settings must include an identity provider";
|
|
272
|
+
}
|
|
273
|
+
let allowed = ["identity", "workers", "pollingIntervalSeconds", "heartbeatRefreshSeconds", "startupTimeoutMs", "shutdownTimeoutMs", "cronMonitorIntervalSeconds", "cleanupIntervalSeconds", "cleanupBatchSize"];
|
|
274
|
+
for (const [key, value] of __entries(settings)) {
|
|
275
|
+
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
276
|
+
throw `Unknown worker option: ${key}`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return { identity: __normalize(settings.identity), workers: integer(__normalize(settings.workers), 2, 1, 128, "workers"), pollingIntervalSeconds: interval(__normalize(settings.pollingIntervalSeconds), 2, 0.5, 3600, "pollingIntervalSeconds"), heartbeatRefreshSeconds: interval(__normalize(settings.heartbeatRefreshSeconds), null, 0.5, 29, "heartbeatRefreshSeconds"), cronMonitorIntervalSeconds: integer(__normalize(settings.cronMonitorIntervalSeconds), 30, 1, 45, "cronMonitorIntervalSeconds"), cleanupIntervalSeconds: integer(__normalize(settings.cleanupIntervalSeconds), 60, 1, 86400, "cleanupIntervalSeconds"), cleanupBatchSize: integer(__normalize(settings.cleanupBatchSize), 1000, 1, 10000, "cleanupBatchSize"), startupTimeoutMs: integer(__normalize(settings.startupTimeoutMs), 30000, 1, 2147483647, "startupTimeoutMs"), shutdownTimeoutMs: integer(__normalize(settings.shutdownTimeoutMs), 30000, 1, 2147483647, "shutdownTimeoutMs") };
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function integer(value, fallback, minimum, maximum, name) {
|
|
284
|
+
__requireArity(arguments.length, [0, 1, 2, 3, 4], "integer");
|
|
285
|
+
value = __boundary(value);
|
|
286
|
+
fallback = __boundary(fallback);
|
|
287
|
+
minimum = __boundary(minimum);
|
|
288
|
+
maximum = __boundary(maximum);
|
|
289
|
+
name = __boundary(name);
|
|
290
|
+
if (__requireBoolean(value === null)) {
|
|
291
|
+
return fallback;
|
|
292
|
+
}
|
|
293
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(value)))) || __requireBoolean(value < minimum)) || __requireBoolean(value > maximum))) {
|
|
294
|
+
throw `Invalid worker option: ${name}`;
|
|
295
|
+
}
|
|
296
|
+
return value;
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function interval(value, fallback, minimum, maximum, name) {
|
|
301
|
+
__requireArity(arguments.length, [0, 1, 2, 3, 4], "interval");
|
|
302
|
+
value = __boundary(value);
|
|
303
|
+
fallback = __boundary(fallback);
|
|
304
|
+
minimum = __boundary(minimum);
|
|
305
|
+
maximum = __boundary(maximum);
|
|
306
|
+
name = __boundary(name);
|
|
307
|
+
if (__requireBoolean(value === null)) {
|
|
308
|
+
return fallback;
|
|
309
|
+
}
|
|
310
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(value))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isFinite(value))))) || __requireBoolean(value < minimum)) || __requireBoolean(value > maximum))) {
|
|
311
|
+
throw `Invalid worker option: ${name}`;
|
|
312
|
+
}
|
|
313
|
+
return value;
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.mjs","sources":["worker.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 \"./dispatcher\"\n class Dispatcher\nimport \"./schedule_sync\"\n synchronizeSchedules(config)\nimport \"./retention\"\n class Retention\nimport \"./management\"\n prepareManagement(config)\nimport js \"node:crypto\" as crypto\nimport js \"@lango-project/lango-server\" as server\nimport js global Number\nimport js global Promise\nimport js global Object\n\nexport class Worker(directory, settings)\n methods\n start()\n close()\n\nWorker(directory, settings)\n @config = loadConfiguration(directory)\n @settings = workerSettings(settings)\n @queues = []\n for @config.targets as target\n if !@queues.includes(target.queue)\n @queues.add(target.queue)\n @executor = new server/Executor(@config.root, {\n identity: @settings.identity\n workers: @settings.workers\n maxQueue: @queues.length * @settings.workers\n startupTimeoutMs: @settings.startupTimeoutMs\n shutdownTimeoutMs: @settings.shutdownTimeoutMs\n queueProvider: queueProvider(@config)\n })\n @dispatcher = new Dispatcher(@config, @executor)\n @state = \"new\"\n @driver = null\n @starting = null\n @closing = null\n @releasing = null\n @closeError = null\n @retention = new Retention(@config, @settings.cleanupIntervalSeconds, @settings.cleanupBatchSize)\n\nworkerSettings(settings)\n if settings == null or !is_object(settings) or is_array(settings)\n throw \"Worker settings must include an identity provider\"\n allowed = [\"identity\", \"workers\", \"pollingIntervalSeconds\", \"heartbeatRefreshSeconds\", \"startupTimeoutMs\", \"shutdownTimeoutMs\", \"cronMonitorIntervalSeconds\", \"cleanupIntervalSeconds\", \"cleanupBatchSize\"]\n for settings as key: value\n if !allowed.includes(key)\n throw \"Unknown worker option: ${key}\"\n return {\n identity: settings.identity\n workers: integer(settings.workers, 2, 1, 128, \"workers\")\n pollingIntervalSeconds: interval(settings.pollingIntervalSeconds, 2, 0.5, 3600, \"pollingIntervalSeconds\")\n heartbeatRefreshSeconds: interval(settings.heartbeatRefreshSeconds, null, 0.5, 29, \"heartbeatRefreshSeconds\")\n cronMonitorIntervalSeconds: integer(settings.cronMonitorIntervalSeconds, 30, 1, 45, \"cronMonitorIntervalSeconds\")\n cleanupIntervalSeconds: integer(settings.cleanupIntervalSeconds, 60, 1, 86400, \"cleanupIntervalSeconds\")\n cleanupBatchSize: integer(settings.cleanupBatchSize, 1000, 1, 10000, \"cleanupBatchSize\")\n startupTimeoutMs: integer(settings.startupTimeoutMs, 30000, 1, 2147483647, \"startupTimeoutMs\")\n shutdownTimeoutMs: integer(settings.shutdownTimeoutMs, 30000, 1, 2147483647, \"shutdownTimeoutMs\")\n }\n\ninteger(value, fallback, minimum, maximum, name)\n if value == null\n return fallback\n if !Number/isSafeInteger(value) or value < minimum or value > maximum\n throw \"Invalid worker option: ${name}\"\n return value\n\ninterval(value, fallback, minimum, maximum, name)\n if value == null\n return fallback\n if !is_number(value) or !Number/isFinite(value) or value < minimum or value > maximum\n throw \"Invalid worker option: ${name}\"\n return value\n\nWorker:start()\n if @state != \"new\"\n return Promise/reject(\"Worker can only be started once\")\n @state = \"starting\"\n @driver = createDriver(@config)\n @starting = launch()\n return @starting\n\nWorker:launch()\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 return @executor.start()\n then(ignored)\n return validateSchedules()\n then(ignored)\n return synchronizeSchedules(@config)\n then(ignored)\n return @retention.start()\n then(ignored)\n return activateConsumer()\n then(ignored)\n pending = Promise/resolve(null)\n for @queues as queue\n pending = subscribe(pending, queue)\n return pending\n then(ignored)\n if @state != \"starting\"\n throw \"Worker closed during startup\"\n @state = \"running\"\n return null\n catch(error)\n @state = \"closing\"\n return chain release()\n finally\n capture error\n throw error\n\nWorker:validateSchedules()\n pending = Promise/resolve(null)\n checked = Object/create(null)\n for @config.schedules as item\n key = to_json([item.identity, item.path])\n if !Object/hasOwn(checked, key)\n checked[key] = true\n pending = validateSchedule(pending, item)\n return pending\n\nWorker:validateSchedule(pending, item)\n return chain pending\n then(ignored)\n capture item\n capture crypto\n return @executor.authorize({\n id: \"schedule-check:${crypto/randomUUID()}\"\n path: item.path\n input: {}\n source: {\n kind: \"system\"\n identity: item.identity\n }\n })\n\nWorker:activateConsumer()\n return chain @driver.stop()\n then(ignored)\n if @state != \"starting\"\n throw \"Worker closed before consumer activation\"\n @driver = createDriver(@config, true, @config.scheduleRevision > 0, @settings.cronMonitorIntervalSeconds)\n return @driver.start()\n\nWorker:subscribe(pending, queue)\n return chain pending\n then(ignored)\n capture queue\n if @state != \"starting\"\n throw \"Worker closed during startup\"\n handler = (jobs)\n capture queue\n return @dispatcher.run(queue, jobs, @driver)\n return @driver.work(queue, {\n includeMetadata: true\n perJobResults: true\n batchSize: 1\n localConcurrency: @settings.workers\n pollingIntervalSeconds: @settings.pollingIntervalSeconds\n heartbeatRefreshSeconds: @settings.heartbeatRefreshSeconds\n }, handler)\n\nWorker: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\nWorker:closeAfter(pending)\n return chain pending\n catch(error)\n return null\n then(ignored)\n return release()\n\nWorker:release()\n if @releasing == null\n @releasing = shutdown()\n return @releasing\n\nWorker:shutdown()\n stops = []\n if @driver != null\n for @queues as queue\n stops.add(@driver.offWork(queue, {\n wait: false\n }))\n return chain Promise/all(stops)\n finally\n return @retention.close()\n catch(error)\n @closeError = error\n return null\n then(ignored)\n return @executor.close()\n catch(error)\n @closeError = error\n return null\n then(ignored)\n if @driver != null\n return @driver.stop({\n graceful: true\n timeout: @settings.shutdownTimeoutMs\n })\n return null\n finally\n @state = \"closed\"\n then(ignored)\n if @closeError != null\n throw @closeError\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"a9ab88c4f795a8c95761f3dce26ace92a387ac8935f67f677290dffda32e4d82","outputHash":"da34638b12783134fa4140bb4dbbf0eaf62a68b50f6b6b08a8db7ef2c6e46c47","mapHash":"e81d4e432c454129db0e0bc1aad47ee51373af2725fddd801648a7e52a607bcb"}}
|
package/docs/guide.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Getting started
|
|
2
|
+
|
|
3
|
+
Lango Boss connects application SQL transactions to PostgreSQL-backed jobs. Start with the [reports application](../examples/reports/README.md), shipped as both Lango source and compiled `dist/` files. It demonstrates HTTP submission, live identity, a separate worker, scheduling, owner status reads, and a local management CLI.
|
|
4
|
+
|
|
5
|
+
## 1. Use the application's PostgreSQL settings
|
|
6
|
+
|
|
7
|
+
Keep a stable package name and one `deploy.xml` for Server and Boss:
|
|
8
|
+
|
|
9
|
+
```xml
|
|
10
|
+
<deploy>
|
|
11
|
+
<database type="postgresql" connectionEnv="APP_DATABASE_URL"/>
|
|
12
|
+
</deploy>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Boss does not have its own connection URL setting. It requires PostgreSQL and Node.js 24+. Use Lango Server 0.2.4 or later; earlier published versions do not contain the required execution/database hooks.
|
|
16
|
+
|
|
17
|
+
## 2. Declare an internal target
|
|
18
|
+
|
|
19
|
+
```xml
|
|
20
|
+
<routes>
|
|
21
|
+
<job path="/reports/create" module="@app/reports"
|
|
22
|
+
handler="createReport" queue="reports" policy="reports"/>
|
|
23
|
+
</routes>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The path is exact and internal. It is not exposed over HTTP. Module and handler selectors come from configuration, not job input. See [internal configuration](https://github.com/lango-project/lango-server/blob/master/docs/jobs.md).
|
|
27
|
+
|
|
28
|
+
## 3. Attach the producer to Server
|
|
29
|
+
|
|
30
|
+
```lango
|
|
31
|
+
import js "@lango-project/lango-boss" as boss
|
|
32
|
+
|
|
33
|
+
attachQueue(directory, builder)
|
|
34
|
+
producer = new boss/Boss(directory)
|
|
35
|
+
return chain producer.start()
|
|
36
|
+
then(ignored)
|
|
37
|
+
capture producer
|
|
38
|
+
capture builder
|
|
39
|
+
producer.configure(builder)
|
|
40
|
+
return producer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Configure the builder's normal HTTP routes/events separately. Retain the producer and close it after HTTP stops. Starting a producer prepares storage; it does not start consumers or cron. See [producer integration](producer.md).
|
|
44
|
+
|
|
45
|
+
## 4. Submit from a handler
|
|
46
|
+
|
|
47
|
+
```lango
|
|
48
|
+
submitReport(input)
|
|
49
|
+
context queue
|
|
50
|
+
start_trans()
|
|
51
|
+
id = queue.send("/reports/create", {
|
|
52
|
+
reportType: input.reportType
|
|
53
|
+
})
|
|
54
|
+
commit_trans()
|
|
55
|
+
return {
|
|
56
|
+
jobId: id
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Validate input and update application data inside the same transaction when those changes must commit with submission. Without an existing transaction, `send()` uses a short transaction of its own. It derives the original identity from the trusted token context and cannot accept a replacement source in input.
|
|
61
|
+
|
|
62
|
+
## 5. Resolve authority on each execution
|
|
63
|
+
|
|
64
|
+
Implement a shared application identity service and register its exported module/handler on the Worker. Read current user/client/grant state, bans, policies, and real authentication time. A null/false result rejects permanently; infrastructure exceptions remain retryable. System profiles must also be resolved explicitly. See the [Server identity contract](https://github.com/lango-project/lango-server/blob/master/docs/jobs.md#live-identity-provider).
|
|
65
|
+
|
|
66
|
+
Do not reconstruct a browser JWT or replace a stale authentication time with now. HTTP authorization and worker authorization may share application logic, but queue execution is independent of HTTP Validate throttling.
|
|
67
|
+
|
|
68
|
+
## 6. Run a worker
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
lango-boss worker /path/to/app --identity-module @app/identity --identity-handler resolveExecutionIdentity
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
An embedded `Worker(directory, settings)` uses the same core. SIGINT/SIGTERM stop admission and drain work within configured bounds. The worker can run without HTTP signing credentials. See [worker execution](worker.md).
|
|
75
|
+
|
|
76
|
+
Handlers use ordinary synchronous Lango SQL. They can read `context job`, the readonly token, log, and queue; nested callbacks inherit the same contexts. Use `job.reject(code)` for controlled permanent failure. Make effects idempotent by job ID or an application operation key: application commits and queue settlement are separate.
|
|
77
|
+
|
|
78
|
+
## 7. Add schedules and read outcomes
|
|
79
|
+
|
|
80
|
+
Put revision-controlled cron definitions in `jobs.xml`. Worker startup validates each system profile/target before activating cron. Use [scheduling](scheduling.md) for deployment and missed-occurrence rules.
|
|
81
|
+
|
|
82
|
+
Owners call `queue.get(id)`. Management functions require `boss.manage`; list pages are bounded and do not expose payloads. Use [status/results](reads.md) and [management](management.md). [Retention cleanup](retention.md) runs with Worker, not the producer alone.
|
|
83
|
+
|
|
84
|
+
## 8. Build before deployment
|
|
85
|
+
|
|
86
|
+
Build application sources in development/CI and deploy generated modules plus XML/package metadata and production dependencies. Server and Boss ship their own compiled runtime. The deployed consumer does not require the compiler when development compilation is disabled.
|
|
87
|
+
|
|
88
|
+
The reports package test installs real tarballs outside the source tree, hides the compiler executable, checks the production dependency tree, runs HTTP/worker/operator processes, and tests the production lockfile offline. See [release preparation](release.md) and the [API reference](reference.md).
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Job, queue, and schedule management
|
|
2
|
+
|
|
3
|
+
Management functions use the current queue/database/token scope, just like [job reads](reads.md). They are package functions, not methods on the producer lifecycle object. Configure the provider with `Boss.configure(builder)` or `Boss.executor(settings)` first.
|
|
4
|
+
|
|
5
|
+
```lango
|
|
6
|
+
import js "@lango-project/lango-boss" as boss
|
|
7
|
+
|
|
8
|
+
retryReport(input)
|
|
9
|
+
return boss/retry(input.jobId)
|
|
10
|
+
|
|
11
|
+
cancelReport(input)
|
|
12
|
+
return boss/cancel(input.jobId)
|
|
13
|
+
|
|
14
|
+
pauseReports(input)
|
|
15
|
+
return boss/pauseQueue("reports")
|
|
16
|
+
|
|
17
|
+
resumeDailyReport(input)
|
|
18
|
+
return boss/resumeSchedule("daily-report")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Every function requires the current token's explicit `boss.manage` policy, including queue/schedule inventory. No browser identity, system profile, SQL connection owner, or producer object becomes an administrator implicitly. HTTP applications must perform their normal live guard checks; the library does not know the application's principal tables or invoke HTTP Validate itself. No HTTP endpoints or management UI are installed automatically.
|
|
22
|
+
|
|
23
|
+
## Jobs
|
|
24
|
+
|
|
25
|
+
`retry(id)` and `cancel(id)` address a version-1 Boss record in this application's schema. Missing, invalid, foreign, and ambiguous IDs return null. Authorization is checked before lookup.
|
|
26
|
+
|
|
27
|
+
| Operation | Current state | Behavior |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `retry(id)` | `failed` | Grant one additional native attempt and move to `retry`. |
|
|
30
|
+
| `retry(id)` | Any other state | Return unchanged state. |
|
|
31
|
+
| `cancel(id)` | `created` or `retry` | Move to `cancelled`; it cannot subsequently be fetched under that queued state. |
|
|
32
|
+
| `cancel(id)` | `active` | Move to `cancelled` and request interruption of the active execution. |
|
|
33
|
+
| `cancel(id)` | `completed`, `failed`, or `cancelled` | Return unchanged state. |
|
|
34
|
+
|
|
35
|
+
The result contains `id`, `queue`, `previousState`, `state`, `changed`, `cancellationRequested`, and `reason`. `cancellationRequested` is true only when an active job was changed to cancelled. Other successful changes are not claims that an executing thread has stopped.
|
|
36
|
+
|
|
37
|
+
Retry requires the stored path and physical queue to remain registered in the caller's running configuration. Otherwise it returns unchanged state with `reason: "TargetUnavailable"`. If the native retry limit cannot be incremented safely, the reason is `RetryLimitExceeded`. Ordinary applied/no-op transitions have a null reason.
|
|
38
|
+
|
|
39
|
+
Retry preserves the job ID, input, and original user/system source. It does not run under the operator's identity, reset the retry counter, or create a new login time. The additional attempt resolves the original principal's live authority again; a ban, revoked grant, missing policy, or stale authentication can still fail it permanently. An operator's permission to request retry is not permission for the original job to execute. Native behavior is described in the [pg-boss job API](https://pgboss.io/api/jobs).
|
|
40
|
+
|
|
41
|
+
Row locks serialize simultaneous job changes with workers, cleanup, and other operators. Two retry requests that encounter the same failed state grant one extra attempt; the second sees the already retried state. Completion can win a race with cancel, in which case cancel returns unchanged completed state. No failed/cancelled job is implicitly restored to success.
|
|
42
|
+
|
|
43
|
+
## Active cancellation
|
|
44
|
+
|
|
45
|
+
Each claimed job has a local claim watcher while it waits/runs in the Executor. Approximately once per second it calls pg-boss's attempt-fenced `touch()` through the existing control driver. This also works for older jobs without a native heartbeat interval. Native heartbeat signals continue to be honored.
|
|
46
|
+
|
|
47
|
+
When the database confirms that the fetched attempt no longer owns an active claim, the watcher aborts that attempt's Executor signal. Queued local execution is prevented; running local code is terminated with its worker thread. Open application SQL transactions are rolled back when the thread's connection closes. The watcher stops and drains its in-flight check when dispatch settles; it creates no permanent extra pool or process-local authority registry.
|
|
48
|
+
|
|
49
|
+
`cancel()` returns after the database change, not after receiving a remote worker's stop acknowledgement. The worker learns about committed cancellation through its next successful claim check or native heartbeat. If cancellation is in an outer application transaction, it is invisible to other workers until commit. During a database outage a failed check is logged and does not prove claim loss; later checks or the normal deadline must resolve it.
|
|
50
|
+
|
|
51
|
+
Already committed SQL and external side effects cannot be undone. Remote side effects can still finish after local cancellation. Attempt fencing prevents the old disposition from completing or failing a newer attempt. Cancellation is not an exactly-once or instantaneous distributed-stop guarantee.
|
|
52
|
+
|
|
53
|
+
The watcher adds roughly one control query per second per dispatched job, including jobs waiting in the local Executor queue. It refreshes the heartbeat timestamp without extending native expiration. Large deployments should measure that workload; network-partition/process-loss testing remains separate work.
|
|
54
|
+
|
|
55
|
+
## Queue pause and resume
|
|
56
|
+
|
|
57
|
+
`pauseQueue(name)` and `resumeQueue(name)` return `{ name, paused, changed }`, or null for a queue not owned by this application's registry.
|
|
58
|
+
|
|
59
|
+
Preparing a configured job target registers its physical queue in the application registry. That ownership is retained when routes are later removed, so old backlog can still be managed. Unrelated native/internal queues are not adopted merely because they share the schema.
|
|
60
|
+
|
|
61
|
+
Pause is a persistent native database setting. It prevents subsequent queue fetches on all replicas, survives process restart, and does not prevent submission. Jobs already fetched, waiting locally, or running continue; use job cancellation when interruption is required. Preparing a producer or worker does not clear the pause. Repeating pause/resume is safe and reports `changed: false` when the requested state already holds. See the [pg-boss queue API](https://pgboss.io/api/queues).
|
|
62
|
+
|
|
63
|
+
## Schedule pause and resume
|
|
64
|
+
|
|
65
|
+
`pauseSchedule(name)` and `resumeSchedule(name)` operate on the currently deployed registry definition, under the same application advisory transaction lock used by XML reconciliation. They do not rewrite `jobs.xml` or increment its revision.
|
|
66
|
+
|
|
67
|
+
The result contains `name`, `paused`, `enabled`, `effectiveEnabled`, and `changed`, or is null when there is no currently present managed definition. `enabled` is the XML setting; `effectiveEnabled` requires XML enabled and management not paused.
|
|
68
|
+
|
|
69
|
+
Pause removes the owned native schedule and stores a persistent operational pause flag. Resume reinstalls the latest deployed definition only if its XML enabled flag is true. It cannot override `enabled="false"`. Repeated calls report unchanged state without clearing or duplicating definitions. Removed definitions retain their tombstone pause state for later reintroduction, but are absent from normal inventory and cannot be resumed while removed.
|
|
70
|
+
|
|
71
|
+
The advisory lock serializes reconciliation and management, so an old replica's management request uses the stored current definition. XML changes preserve operational pause. The native scan/cache lease can still emit work from an already read schedule; pause does not cancel such emissions or previously queued work. See [scheduling](scheduling.md) for revision and deployment rules.
|
|
72
|
+
|
|
73
|
+
## Inventory
|
|
74
|
+
|
|
75
|
+
`queues(options)` and `schedules(options)` return `{ items, nextCursor }`. Both accept only optional `limit` (default 50, range 1–200) and `cursor` (the previous page's returned name). Ordering is ascending by name; null next cursor ends traversal. No offset or total-count contract is provided. Cursor names are navigation positions, not access credentials; every call checks authorization and stays in the current application schema.
|
|
76
|
+
|
|
77
|
+
Queue items contain `name`, `paused`, `queued` (created/retry), `active`, and `failed` counts. Counts include only matching Boss application/version records, not unrelated native payloads. Schedule items contain `name`, `queue`, `path`, `cron`, `timeZone`, `enabled`, `paused`, and `effectiveEnabled`; they omit input data and removed definitions. Inventory is a current view, not a cross-page transaction snapshot. Limits bound returned items, not the cost of aggregate queries.
|
|
78
|
+
|
|
79
|
+
## Transactions and audit
|
|
80
|
+
|
|
81
|
+
Mutations join the current usable application SQL transaction. When no transaction is open, they create and commit a short one of their own. A rollback also rolls back job state, pause settings/native schedule changes, and their durable audit rows. Callers must roll back their transaction after a failed management operation. Queue notifications follow commit; no speculative local abort is issued from an uncommitted request.
|
|
82
|
+
|
|
83
|
+
Each valid mutation attempt, including an unchanged or missing target, inserts into the application's `lango_management_audit` table. It stores application, action, target, actor identity references, outcome metadata, and a timestamp. It does not copy input/result payloads, JWTs, cookies, client proofs, policies, or passwords. The actor records the manager; it never replaces the source attached to the job. Audit-write failure fails and rolls back an owned operation instead of silently applying an unaudited change.
|
|
84
|
+
|
|
85
|
+
Permission denial is logged as a warning without looking up a target. Management failures are logged at error level; verbose logs identify staged mutations. A staged log is not a commit receipt when an outer transaction remains open. Invalid arguments do not create durable mutation rows. Read/inventory access auditing and an audit retention/export policy are not automatic; applications/operators should manage those separately. The table is transactional application storage, not a tamper-proof external audit service.
|
|
86
|
+
|
|
87
|
+
## Verification
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
LANGO_TEST_POSTGRES='postgresql://user@127.0.0.1/test_database' npm run test:management
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The real PostgreSQL tests cover original-identity retry and later permission loss, state/no-op transitions, transaction/audit rollback, concurrent retry, native queue pause across startup, schedule/XML interleaving and disabled definitions, application/registry scope, bounded inventory, blocking legacy-job cancellation, and audit-storage failure. They are also part of `test:postgres`.
|