@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,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.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from "./.lango/entries/app.mjs";
|
|
3
|
+
export * from "./.lango/entries/app.mjs";
|
|
4
|
+
import { configure } from "./.lango/runtime.mjs";
|
|
5
|
+
configure({ output: (value) => console.log(value) });
|
|
6
|
+
await main(process.argv.slice(2));
|
|
7
|
+
//# sourceMappingURL=app.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.mjs","sources":["app.lango"],"sourcesContent":["import js \"@lango-project/lango-boss\" as boss\nimport js \"@lango-project/lango-server\" as server\nimport js \"node:path\" as path\nimport js \"node:crypto\" as crypto\nimport js global process\nimport \"./setup\"\n initialize()\n\nexport main(args)\n\nmain(args)\n directory = process.cwd()\n if args.length == 1 and args[0] == \"setup\"\n return server/withDatabase(directory, initialize)\n if args.length == 1 and args[0] == \"server\"\n return serve(directory)\n if args.length >= 2 and args[0] == \"operator\"\n return operate(directory, args)\n throw \"Usage: node dist/app.mjs setup|server|operator <action> [target]\"\n\nserve(directory)\n producer = new boss/Boss(directory)\n state = {\n http: null\n stopping: false\n }\n stop = ()\n capture state\n if state.stopping\n return null\n state.stopping = true\n return chain state.http.close()\n finally\n capture producer\n return producer.close()\n catch(error)\n process.stderr.write(\"Report server shutdown failed: ${error}\\n\")\n process.exitCode = 1\n return chain producer.start()\n then(ignored)\n capture producer\n capture state\n capture directory\n builder = new server/Builder(directory)\n builder.loadDeployment()\n builder.addMiddleware(\"client\", {\n module: \"./dist/handlers.mjs\"\n handler: \"guard\"\n })\n builder.event({\n name: \"register\"\n module: \"./dist/handlers.mjs\"\n handler: \"register\"\n })\n for [\"submit\", \"status\", \"whoami\"] as handler\n builder.endpoint({\n path: \"/${handler}\"\n module: \"./dist/handlers.mjs\"\n handler: handler\n policy: \"anonymous\"\n middleware: \"client\"\n })\n producer.configure(builder)\n state.http = builder.build()\n return state.http.start()\n then(address)\n capture stop\n println(\"Listening on ${address.address}:${address.port}\")\n process.once(\"SIGTERM\", stop)\n process.once(\"SIGINT\", stop)\n catch(error)\n capture producer\n return chain producer.close()\n finally\n capture state\n if state.http != null\n return state.http.close()\n return null\n finally\n capture error\n throw error\n\noperate(directory, args)\n action = args[1]\n read = [\"jobs\", \"queues\", \"schedules\"]\n changes = [\"job\", \"retry\", \"cancel\", \"pauseQueue\", \"resumeQueue\", \"pauseSchedule\", \"resumeSchedule\"]\n if (!read.includes(action) and !changes.includes(action)) or args.length > 3\n throw \"Unknown operator action\"\n if changes.includes(action) and args.length != 3\n throw \"Operator action requires a target\"\n producer = new boss/Boss(directory)\n state = {\n executor: null\n }\n return chain producer.start()\n then(ignored)\n capture producer\n capture state\n state.executor = producer.executor({\n identity: {\n module: \"./dist/handlers.mjs\"\n handler: \"identity\"\n }\n workers: 1\n })\n return state.executor.start()\n then(ignored)\n capture state\n capture args\n capture action\n capture crypto\n return state.executor.execute({\n id: \"operator:${crypto/randomUUID()}\"\n path: \"/operator\"\n input: {\n action: action\n target: args[2]\n }\n source: {\n kind: \"system\"\n identity: \"operator\"\n }\n })\n then(result)\n println(to_json(result))\n finally\n capture state\n if state.executor != null\n return state.executor.close()\n return null\n finally\n capture producer\n return producer.close()\n"],"names":[],"mappings":"","x_lango_build":{"fingerprint":"c19cf4ff4c5b25ad9013253a961154319b665479309966a56bcd78ce86e003db","outputHash":"e424ab0bd864befc1ced04a5f02fc554cf0776070ad0d36f810eda914f387e90","mapHash":"9c1a0db8652a314aa372a0ffa786088dfe8d862980087986d93942f27c7379e1"}}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as boss from "@lango-project/lango-boss";
|
|
2
|
+
import {
|
|
3
|
+
hostGlobal as __hostGlobal,
|
|
4
|
+
contextGet as __contextGet,
|
|
5
|
+
contextSet as __contextSet,
|
|
6
|
+
contextRestore as __contextRestore,
|
|
7
|
+
isNumber as __isNumber,
|
|
8
|
+
isString as __isString,
|
|
9
|
+
isBool as __isBool,
|
|
10
|
+
isObject as __isObject,
|
|
11
|
+
isArray as __isArray,
|
|
12
|
+
requireBoolean as __requireBoolean,
|
|
13
|
+
normalize as __normalize,
|
|
14
|
+
finite as __finite,
|
|
15
|
+
call as __call,
|
|
16
|
+
boundary as __boundary,
|
|
17
|
+
startTrans as __startTrans,
|
|
18
|
+
commitTrans as __commitTrans,
|
|
19
|
+
rollbackTrans as __rollbackTrans,
|
|
20
|
+
transState as __transState,
|
|
21
|
+
query as __query,
|
|
22
|
+
requireArity as __requireArity,
|
|
23
|
+
} from "./.lango/runtime.mjs";
|
|
24
|
+
|
|
25
|
+
export function register(input) {
|
|
26
|
+
const __contextScope = [];
|
|
27
|
+
try {
|
|
28
|
+
__requireArity(arguments.length, [0], "register");
|
|
29
|
+
input = __boundary(input);
|
|
30
|
+
let row = __query("insert into boss_demo_clients (client_id, registered_ip, user_agent)\nvalues (:id, :ip, :agent) on conflict do nothing", ["id","ip","agent"]);
|
|
31
|
+
row.id = __normalize(__contextGet("token").clientId);
|
|
32
|
+
row.ip = __normalize(input.ip);
|
|
33
|
+
row.agent = __normalize(input.userAgent);
|
|
34
|
+
__normalize(row.execute());
|
|
35
|
+
__normalize(__contextGet("token").addPolicy("reports"));
|
|
36
|
+
return null;
|
|
37
|
+
return null;
|
|
38
|
+
} finally {
|
|
39
|
+
__contextRestore(__contextScope);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function client(id) {
|
|
44
|
+
__requireArity(arguments.length, [0], "client");
|
|
45
|
+
id = __boundary(id);
|
|
46
|
+
let query = __query("select banned, can_submit from boss_demo_clients where client_id = :id", ["id"]);
|
|
47
|
+
query.id = id;
|
|
48
|
+
__normalize(query.execute());
|
|
49
|
+
return __requireBoolean(__requireBoolean(__normalize(query.next())) && __requireBoolean(!__requireBoolean(__normalize(query.banned)))) && __requireBoolean(__normalize(query.can_submit));
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function guard(handler, path, input, represent = null) {
|
|
54
|
+
const __contextScope = [];
|
|
55
|
+
try {
|
|
56
|
+
__requireArity(arguments.length, [0, 1, 2], "guard");
|
|
57
|
+
handler = __boundary(handler);
|
|
58
|
+
path = __boundary(path);
|
|
59
|
+
input = __boundary(input);
|
|
60
|
+
represent = __boundary(represent);
|
|
61
|
+
if (__requireBoolean(!__requireBoolean(client(__normalize(__contextGet("token").clientId))))) {
|
|
62
|
+
__normalize(__contextGet("response").reject(403, "ClientRejected"));
|
|
63
|
+
}
|
|
64
|
+
return __call(handler, input);
|
|
65
|
+
return null;
|
|
66
|
+
} finally {
|
|
67
|
+
__contextRestore(__contextScope);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function whoami(input) {
|
|
72
|
+
const __contextScope = [];
|
|
73
|
+
try {
|
|
74
|
+
__requireArity(arguments.length, [0], "whoami");
|
|
75
|
+
input = __boundary(input);
|
|
76
|
+
return { clientId: __normalize(__contextGet("token").clientId) };
|
|
77
|
+
return null;
|
|
78
|
+
} finally {
|
|
79
|
+
__contextRestore(__contextScope);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function submit(input) {
|
|
84
|
+
const __contextScope = [];
|
|
85
|
+
try {
|
|
86
|
+
__requireArity(arguments.length, [0], "submit");
|
|
87
|
+
input = __boundary(input);
|
|
88
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(input.message)))) || __requireBoolean(input.message.length === 0)) || __requireBoolean(input.message.length > 200))) {
|
|
89
|
+
__normalize(__contextGet("response").reject(400, "InvalidMessage"));
|
|
90
|
+
}
|
|
91
|
+
if (__requireBoolean(__requireBoolean(__normalize(input.failOnce) !== null) && __requireBoolean(!__requireBoolean(__isBool(__normalize(input.failOnce)))))) {
|
|
92
|
+
__normalize(__contextGet("response").reject(400, "InvalidFailOnce"));
|
|
93
|
+
}
|
|
94
|
+
__startTrans();
|
|
95
|
+
let now = __normalize(__hostGlobal(["Date"]).now());
|
|
96
|
+
let quota = __query("update boss_demo_clients set\n submissions = case when window_started <= :cutoff then 1 else submissions + 1 end,\n window_started = case when window_started <= :cutoff then :now else window_started end\nwhere client_id = :id returning submissions", ["cutoff","now","id"]);
|
|
97
|
+
quota.id = __normalize(__contextGet("token").clientId);
|
|
98
|
+
quota.now = now;
|
|
99
|
+
quota.cutoff = __finite(now - 60000);
|
|
100
|
+
__normalize(quota.execute());
|
|
101
|
+
__normalize(quota.next());
|
|
102
|
+
if (__requireBoolean(__normalize(quota.submissions) > 3)) {
|
|
103
|
+
__rollbackTrans();
|
|
104
|
+
__normalize(__contextGet("response").reject(429, "SubmissionLimit"));
|
|
105
|
+
}
|
|
106
|
+
let id = __normalize(__contextGet("queue").send("/reports/create", { message: __normalize(input.message), failOnce: __normalize(input.failOnce) === true }));
|
|
107
|
+
__commitTrans();
|
|
108
|
+
return { jobId: id };
|
|
109
|
+
return null;
|
|
110
|
+
} finally {
|
|
111
|
+
__contextRestore(__contextScope);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function status(input) {
|
|
116
|
+
const __contextScope = [];
|
|
117
|
+
try {
|
|
118
|
+
__requireArity(arguments.length, [0], "status");
|
|
119
|
+
input = __boundary(input);
|
|
120
|
+
return __normalize(__contextGet("queue").get(__normalize(input.jobId)));
|
|
121
|
+
return null;
|
|
122
|
+
} finally {
|
|
123
|
+
__contextRestore(__contextScope);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function identity(input) {
|
|
128
|
+
__requireArity(arguments.length, [0], "identity");
|
|
129
|
+
input = __boundary(input);
|
|
130
|
+
let source = __normalize(input.source);
|
|
131
|
+
if (__requireBoolean(__normalize(source.kind) === "system")) {
|
|
132
|
+
if (__normalize(source.identity) === "job_user") {
|
|
133
|
+
return { identity: "job_user", policies: ["reports"] };
|
|
134
|
+
} else if (__normalize(source.identity) === "operator") {
|
|
135
|
+
return { identity: "operator", policies: ["boss.manage"] };
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(source.userId) !== null) || __requireBoolean(__normalize(source.grantId) !== null)) || __requireBoolean(!__requireBoolean(client(__normalize(source.clientId)))))) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return { clientId: __normalize(source.clientId), policies: ["reports"] };
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function createReport(input) {
|
|
147
|
+
const __contextScope = [];
|
|
148
|
+
try {
|
|
149
|
+
__requireArity(arguments.length, [0], "createReport");
|
|
150
|
+
input = __boundary(input);
|
|
151
|
+
if (__requireBoolean(__requireBoolean(__normalize(input.failOnce) === true) && __requireBoolean(__normalize(__contextGet("job").attempt) === 1))) {
|
|
152
|
+
__normalize(__contextGet("job").reject("DemoFailure"));
|
|
153
|
+
}
|
|
154
|
+
__startTrans();
|
|
155
|
+
let insert = __query("insert into boss_demo_reports (job_id, client_id, profile, message)\nvalues (:id, :client, :profile, :message) on conflict (job_id) do nothing", ["id","client","profile","message"]);
|
|
156
|
+
insert.id = __normalize(__contextGet("job").id);
|
|
157
|
+
insert.client = __normalize(__contextGet("token").clientId);
|
|
158
|
+
insert.profile = __normalize(__contextGet("token").get("identity"));
|
|
159
|
+
insert.message = __normalize(input.message);
|
|
160
|
+
__normalize(insert.execute());
|
|
161
|
+
let row = __query("select message, client_id, profile from boss_demo_reports where job_id = :id", ["id"]);
|
|
162
|
+
row.id = __normalize(__contextGet("job").id);
|
|
163
|
+
__normalize(row.execute());
|
|
164
|
+
__normalize(row.next());
|
|
165
|
+
let result = { message: __normalize(row.message), clientId: __normalize(row.client_id), profile: __normalize(row.profile) };
|
|
166
|
+
__commitTrans();
|
|
167
|
+
return result;
|
|
168
|
+
return null;
|
|
169
|
+
} finally {
|
|
170
|
+
__contextRestore(__contextScope);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function operator(input) {
|
|
175
|
+
__requireArity(arguments.length, [0], "operator");
|
|
176
|
+
input = __boundary(input);
|
|
177
|
+
if (__normalize(input.action) === "jobs") {
|
|
178
|
+
return __normalize(boss.jobs(__normalize(input.options)));
|
|
179
|
+
} else if (__normalize(input.action) === "job") {
|
|
180
|
+
return __normalize(boss.job(__normalize(input.target)));
|
|
181
|
+
} else if (__normalize(input.action) === "retry") {
|
|
182
|
+
return __normalize(boss.retry(__normalize(input.target)));
|
|
183
|
+
} else if (__normalize(input.action) === "cancel") {
|
|
184
|
+
return __normalize(boss.cancel(__normalize(input.target)));
|
|
185
|
+
} else if (__normalize(input.action) === "queues") {
|
|
186
|
+
return __normalize(boss.queues());
|
|
187
|
+
} else if (__normalize(input.action) === "schedules") {
|
|
188
|
+
return __normalize(boss.schedules());
|
|
189
|
+
} else if (__normalize(input.action) === "pauseQueue") {
|
|
190
|
+
return __normalize(boss.pauseQueue(__normalize(input.target)));
|
|
191
|
+
} else if (__normalize(input.action) === "resumeQueue") {
|
|
192
|
+
return __normalize(boss.resumeQueue(__normalize(input.target)));
|
|
193
|
+
} else if (__normalize(input.action) === "pauseSchedule") {
|
|
194
|
+
return __normalize(boss.pauseSchedule(__normalize(input.target)));
|
|
195
|
+
} else if (__normalize(input.action) === "resumeSchedule") {
|
|
196
|
+
return __normalize(boss.resumeSchedule(__normalize(input.target)));
|
|
197
|
+
} else {
|
|
198
|
+
throw "Unknown operator action";
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=handlers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.mjs","sources":["handlers.lango"],"sourcesContent":["import js \"@lango-project/lango-boss\" as boss\nimport js global Date\n\nexport register(input)\nexport guard(handler, path, input, represent = null)\nexport submit(input)\nexport status(input)\nexport whoami(input)\nexport identity(input)\nexport createReport(input)\nexport operator(input)\n\nregister(input)\n context token\n row = SQL\n insert into boss_demo_clients (client_id, registered_ip, user_agent)\n values (:id, :ip, :agent) on conflict do nothing\n row.id = token.clientId?\n row.ip = input.ip\n row.agent = input.userAgent\n row.execute()\n token.addPolicy(\"reports\")\n return null\n\nclient(id)\n query = SQL\n select banned, can_submit from boss_demo_clients where client_id = :id\n query.id = id\n query.execute()\n return query.next() and !query.banned and query.can_submit\n\nguard(handler, path, input, represent = null)\n context token\n context response\n if !client(token.clientId?)\n response.reject(403, \"ClientRejected\")\n return handler(input)\n\nwhoami(input)\n context token\n return {\n clientId: token.clientId?\n }\n\nsubmit(input)\n context response\n context token\n context queue\n if !is_string(input.message) or input.message.length == 0 or input.message.length > 200\n response.reject(400, \"InvalidMessage\")\n if input.failOnce != null and !is_bool(input.failOnce)\n response.reject(400, \"InvalidFailOnce\")\n start_trans()\n now = Date/now()\n quota = SQL\n update boss_demo_clients set\n submissions = case when window_started <= :cutoff then 1 else submissions + 1 end,\n window_started = case when window_started <= :cutoff then :now else window_started end\n where client_id = :id returning submissions\n quota.id = token.clientId?\n quota.now = now\n quota.cutoff = now - 60000\n quota.execute()\n quota.next()\n if quota.submissions > 3\n rollback_trans()\n response.reject(429, \"SubmissionLimit\")\n id = queue.send(\"/reports/create\", {\n message: input.message\n failOnce: input.failOnce == true\n })\n commit_trans()\n return {\n jobId: id\n }\n\nstatus(input)\n context queue\n return queue.get(input.jobId)\n\nidentity(input)\n source = input.source\n if source.kind == \"system\"\n switch source.identity\n case \"job_user\"\n return {\n identity: \"job_user\"\n policies: [\"reports\"]\n }\n case \"operator\"\n return {\n identity: \"operator\"\n policies: [\"boss.manage\"]\n }\n return null\n if source.userId != null or source.grantId != null or !client(source.clientId)\n return null\n return {\n clientId: source.clientId\n policies: [\"reports\"]\n }\n\ncreateReport(input)\n context job\n context token\n if input.failOnce == true and job.attempt? == 1\n job.reject(\"DemoFailure\")\n start_trans()\n insert = SQL\n insert into boss_demo_reports (job_id, client_id, profile, message)\n values (:id, :client, :profile, :message) on conflict (job_id) do nothing\n insert.id = job.id?\n insert.client = token.clientId?\n insert.profile = token.get(\"identity\")\n insert.message = input.message\n insert.execute()\n row = SQL\n select message, client_id, profile from boss_demo_reports where job_id = :id\n row.id = job.id?\n row.execute()\n row.next()\n result = {\n message: row.message\n clientId: row.client_id\n profile: row.profile\n }\n commit_trans()\n return result\n\noperator(input)\n switch input.action\n case \"jobs\"\n return boss/jobs(input.options)\n case \"job\"\n return boss/job(input.target)\n case \"retry\"\n return boss/retry(input.target)\n case \"cancel\"\n return boss/cancel(input.target)\n case \"queues\"\n return boss/queues()\n case \"schedules\"\n return boss/schedules()\n case \"pauseQueue\"\n return boss/pauseQueue(input.target)\n case \"resumeQueue\"\n return boss/resumeQueue(input.target)\n case \"pauseSchedule\"\n return boss/pauseSchedule(input.target)\n case \"resumeSchedule\"\n return boss/resumeSchedule(input.target)\n else\n throw \"Unknown operator action\"\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;AAYA;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA;;;;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"3e58e66601e671be41962c5e448fd52ce3eec47d6f79c1e836f64743f58ceded","outputHash":"5e5d65f9c893ad726b953af423c2ace943a006eeaec4e32eec516ee2bc68ab95","mapHash":"bd309cf73b6de04ee98cc1df7e9044b5c31b6e50df87b51cad91d8c20f06a5ee"}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalize as __normalize,
|
|
3
|
+
query as __query,
|
|
4
|
+
} from "./.lango/runtime.mjs";
|
|
5
|
+
|
|
6
|
+
export function initialize() {
|
|
7
|
+
let clients = __query("create table if not exists boss_demo_clients (\n client_id text primary key, banned boolean not null default false,\n can_submit boolean not null default true, registered_ip text, user_agent text,\n window_started bigint not null default 0, submissions integer not null default 0\n)", []);
|
|
8
|
+
__normalize(clients.execute());
|
|
9
|
+
let reports = __query("create table if not exists boss_demo_reports (\n job_id text primary key, client_id text, profile text, message text not null,\n created_at timestamptz not null default now()\n)", []);
|
|
10
|
+
__normalize(reports.execute());
|
|
11
|
+
return null;
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=setup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.mjs","sources":["setup.lango"],"sourcesContent":["export initialize()\n\ninitialize()\n clients = SQL\n create table if not exists boss_demo_clients (\n client_id text primary key, banned boolean not null default false,\n can_submit boolean not null default true, registered_ip text, user_agent text,\n window_started bigint not null default 0, submissions integer not null default 0\n )\n clients.execute()\n reports = SQL\n create table if not exists boss_demo_reports (\n job_id text primary key, client_id text, profile text, message text not null,\n created_at timestamptz not null default now()\n )\n reports.execute()\n return null\n"],"names":[],"mappings":";;;;;AAEA;;;;;;;;;","x_lango_build":{"fingerprint":"4c654c6a8a87719c4933f4f1af7d14ec03d03e99a01a168bf12541c05aa91c2b","outputHash":"117838224bf779ff148a6a0bd78bfe7db0eb8cbfb359bd98a536afbe98d22eb3","mapHash":"68167f35d9d934b0ba85269d5e7b8515f3a123518dc8b38745449646bc07bb8b"}}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import js "@lango-project/lango-boss" as boss
|
|
2
|
+
import js global Date
|
|
3
|
+
|
|
4
|
+
export register(input)
|
|
5
|
+
export guard(handler, path, input, represent = null)
|
|
6
|
+
export submit(input)
|
|
7
|
+
export status(input)
|
|
8
|
+
export whoami(input)
|
|
9
|
+
export identity(input)
|
|
10
|
+
export createReport(input)
|
|
11
|
+
export operator(input)
|
|
12
|
+
|
|
13
|
+
register(input)
|
|
14
|
+
context token
|
|
15
|
+
row = SQL
|
|
16
|
+
insert into boss_demo_clients (client_id, registered_ip, user_agent)
|
|
17
|
+
values (:id, :ip, :agent) on conflict do nothing
|
|
18
|
+
row.id = token.clientId?
|
|
19
|
+
row.ip = input.ip
|
|
20
|
+
row.agent = input.userAgent
|
|
21
|
+
row.execute()
|
|
22
|
+
token.addPolicy("reports")
|
|
23
|
+
return null
|
|
24
|
+
|
|
25
|
+
client(id)
|
|
26
|
+
query = SQL
|
|
27
|
+
select banned, can_submit from boss_demo_clients where client_id = :id
|
|
28
|
+
query.id = id
|
|
29
|
+
query.execute()
|
|
30
|
+
return query.next() and !query.banned and query.can_submit
|
|
31
|
+
|
|
32
|
+
guard(handler, path, input, represent = null)
|
|
33
|
+
context token
|
|
34
|
+
context response
|
|
35
|
+
if !client(token.clientId?)
|
|
36
|
+
response.reject(403, "ClientRejected")
|
|
37
|
+
return handler(input)
|
|
38
|
+
|
|
39
|
+
whoami(input)
|
|
40
|
+
context token
|
|
41
|
+
return {
|
|
42
|
+
clientId: token.clientId?
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
submit(input)
|
|
46
|
+
context response
|
|
47
|
+
context token
|
|
48
|
+
context queue
|
|
49
|
+
if !is_string(input.message) or input.message.length == 0 or input.message.length > 200
|
|
50
|
+
response.reject(400, "InvalidMessage")
|
|
51
|
+
if input.failOnce != null and !is_bool(input.failOnce)
|
|
52
|
+
response.reject(400, "InvalidFailOnce")
|
|
53
|
+
start_trans()
|
|
54
|
+
now = Date/now()
|
|
55
|
+
quota = SQL
|
|
56
|
+
update boss_demo_clients set
|
|
57
|
+
submissions = case when window_started <= :cutoff then 1 else submissions + 1 end,
|
|
58
|
+
window_started = case when window_started <= :cutoff then :now else window_started end
|
|
59
|
+
where client_id = :id returning submissions
|
|
60
|
+
quota.id = token.clientId?
|
|
61
|
+
quota.now = now
|
|
62
|
+
quota.cutoff = now - 60000
|
|
63
|
+
quota.execute()
|
|
64
|
+
quota.next()
|
|
65
|
+
if quota.submissions > 3
|
|
66
|
+
rollback_trans()
|
|
67
|
+
response.reject(429, "SubmissionLimit")
|
|
68
|
+
id = queue.send("/reports/create", {
|
|
69
|
+
message: input.message
|
|
70
|
+
failOnce: input.failOnce == true
|
|
71
|
+
})
|
|
72
|
+
commit_trans()
|
|
73
|
+
return {
|
|
74
|
+
jobId: id
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
status(input)
|
|
78
|
+
context queue
|
|
79
|
+
return queue.get(input.jobId)
|
|
80
|
+
|
|
81
|
+
identity(input)
|
|
82
|
+
source = input.source
|
|
83
|
+
if source.kind == "system"
|
|
84
|
+
switch source.identity
|
|
85
|
+
case "job_user"
|
|
86
|
+
return {
|
|
87
|
+
identity: "job_user"
|
|
88
|
+
policies: ["reports"]
|
|
89
|
+
}
|
|
90
|
+
case "operator"
|
|
91
|
+
return {
|
|
92
|
+
identity: "operator"
|
|
93
|
+
policies: ["boss.manage"]
|
|
94
|
+
}
|
|
95
|
+
return null
|
|
96
|
+
if source.userId != null or source.grantId != null or !client(source.clientId)
|
|
97
|
+
return null
|
|
98
|
+
return {
|
|
99
|
+
clientId: source.clientId
|
|
100
|
+
policies: ["reports"]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
createReport(input)
|
|
104
|
+
context job
|
|
105
|
+
context token
|
|
106
|
+
if input.failOnce == true and job.attempt? == 1
|
|
107
|
+
job.reject("DemoFailure")
|
|
108
|
+
start_trans()
|
|
109
|
+
insert = SQL
|
|
110
|
+
insert into boss_demo_reports (job_id, client_id, profile, message)
|
|
111
|
+
values (:id, :client, :profile, :message) on conflict (job_id) do nothing
|
|
112
|
+
insert.id = job.id?
|
|
113
|
+
insert.client = token.clientId?
|
|
114
|
+
insert.profile = token.get("identity")
|
|
115
|
+
insert.message = input.message
|
|
116
|
+
insert.execute()
|
|
117
|
+
row = SQL
|
|
118
|
+
select message, client_id, profile from boss_demo_reports where job_id = :id
|
|
119
|
+
row.id = job.id?
|
|
120
|
+
row.execute()
|
|
121
|
+
row.next()
|
|
122
|
+
result = {
|
|
123
|
+
message: row.message
|
|
124
|
+
clientId: row.client_id
|
|
125
|
+
profile: row.profile
|
|
126
|
+
}
|
|
127
|
+
commit_trans()
|
|
128
|
+
return result
|
|
129
|
+
|
|
130
|
+
operator(input)
|
|
131
|
+
switch input.action
|
|
132
|
+
case "jobs"
|
|
133
|
+
return boss/jobs(input.options)
|
|
134
|
+
case "job"
|
|
135
|
+
return boss/job(input.target)
|
|
136
|
+
case "retry"
|
|
137
|
+
return boss/retry(input.target)
|
|
138
|
+
case "cancel"
|
|
139
|
+
return boss/cancel(input.target)
|
|
140
|
+
case "queues"
|
|
141
|
+
return boss/queues()
|
|
142
|
+
case "schedules"
|
|
143
|
+
return boss/schedules()
|
|
144
|
+
case "pauseQueue"
|
|
145
|
+
return boss/pauseQueue(input.target)
|
|
146
|
+
case "resumeQueue"
|
|
147
|
+
return boss/resumeQueue(input.target)
|
|
148
|
+
case "pauseSchedule"
|
|
149
|
+
return boss/pauseSchedule(input.target)
|
|
150
|
+
case "resumeSchedule"
|
|
151
|
+
return boss/resumeSchedule(input.target)
|
|
152
|
+
else
|
|
153
|
+
throw "Unknown operator action"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lango-example/boss-reports",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/handlers.mjs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "lango build app.lango --out dist/app.mjs --executable && lango build handlers.lango --out dist/handlers.mjs",
|
|
11
|
+
"setup": "node dist/app.mjs setup",
|
|
12
|
+
"start": "node dist/app.mjs server",
|
|
13
|
+
"worker": "lango-boss worker . --identity-module ./dist/handlers.mjs --identity-handler identity",
|
|
14
|
+
"operator": "node dist/app.mjs operator"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lango-project/lango-boss": "^0.1.0",
|
|
18
|
+
"@lango-project/lango-server": "^0.2.4"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@lango-project/lango-js": "^0.2.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export initialize()
|
|
2
|
+
|
|
3
|
+
initialize()
|
|
4
|
+
clients = SQL
|
|
5
|
+
create table if not exists boss_demo_clients (
|
|
6
|
+
client_id text primary key, banned boolean not null default false,
|
|
7
|
+
can_submit boolean not null default true, registered_ip text, user_agent text,
|
|
8
|
+
window_started bigint not null default 0, submissions integer not null default 0
|
|
9
|
+
)
|
|
10
|
+
clients.execute()
|
|
11
|
+
reports = SQL
|
|
12
|
+
create table if not exists boss_demo_reports (
|
|
13
|
+
job_id text primary key, client_id text, profile text, message text not null,
|
|
14
|
+
created_at timestamptz not null default now()
|
|
15
|
+
)
|
|
16
|
+
reports.execute()
|
|
17
|
+
return null
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lango-project/lango-boss",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "PostgreSQL-backed jobs and queues for Lango applications.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=24"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/library.mjs",
|
|
15
|
+
"./queue": "./dist/queue.mjs",
|
|
16
|
+
"./transaction": "./dist/transaction.mjs",
|
|
17
|
+
"./schedule-transaction": "./dist/schedule_transaction.mjs",
|
|
18
|
+
"./management-transaction": "./dist/management_transaction.mjs"
|
|
19
|
+
},
|
|
20
|
+
"lango": {
|
|
21
|
+
"source": "src/library.lango",
|
|
22
|
+
"output": "dist/library.mjs"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"lango-boss": "dist/cli.mjs"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist/**",
|
|
29
|
+
"src/*.lango",
|
|
30
|
+
"docs/**",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"NOTICE",
|
|
34
|
+
"examples/reports/*.lango",
|
|
35
|
+
"examples/reports/*.xml",
|
|
36
|
+
"examples/reports/package.json",
|
|
37
|
+
"examples/reports/README.md",
|
|
38
|
+
"examples/reports/dist/**"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"clean": "lango run tools/clean.lango",
|
|
42
|
+
"build:clean": "npm run clean && npm run build",
|
|
43
|
+
"build": "lango build --project",
|
|
44
|
+
"test": "npm run build && lango test src/test/configuration.lango --build-dir .test-output/configuration && lango test src/test/envelope.lango --build-dir .test-output/envelope",
|
|
45
|
+
"prepack": "npm run build:clean",
|
|
46
|
+
"test:postgres": "npm run build && lango build src/test/producer_handlers.lango --out .test-output/producer_handlers.mjs && lango test src/test/producer.lango --build-dir .test-output/producer && lango build src/test/worker_handlers.lango --out .test-output/worker_handlers.mjs && lango test src/test/worker.lango --build-dir .test-output/worker && lango build src/test/schedule_handlers.lango --out .test-output/schedule_handlers.mjs && lango test src/test/scheduling.lango --build-dir .test-output/scheduling && lango test src/test/retention.lango --build-dir .test-output/retention && lango build src/test/read_handlers.lango --out .test-output/read_handlers.mjs && lango test src/test/reads.lango --build-dir .test-output/reads && lango build src/test/management_handlers.lango --out .test-output/management_handlers.mjs && lango test src/test/management.lango --build-dir .test-output/management",
|
|
47
|
+
"test:workers": "npm run build && lango build src/test/worker_handlers.lango --out .test-output/worker_handlers.mjs && lango test src/test/worker.lango --build-dir .test-output/worker",
|
|
48
|
+
"test:schedules": "npm run build && lango build src/test/schedule_handlers.lango --out .test-output/schedule_handlers.mjs && lango test src/test/scheduling.lango --build-dir .test-output/scheduling",
|
|
49
|
+
"test:retention": "npm run build && lango build src/test/schedule_handlers.lango --out .test-output/schedule_handlers.mjs && lango test src/test/retention.lango --build-dir .test-output/retention",
|
|
50
|
+
"test:reads": "npm run build && lango build src/test/read_handlers.lango --out .test-output/read_handlers.mjs && lango test src/test/reads.lango --build-dir .test-output/reads",
|
|
51
|
+
"test:management": "npm run build && lango build src/test/management_handlers.lango --out .test-output/management_handlers.mjs && lango test src/test/management.lango --build-dir .test-output/management",
|
|
52
|
+
"test:package": "npm run build && lango test src/test/package.lango --build-dir .test-output/package",
|
|
53
|
+
"stage:server": "lango run tools/stage_server.lango --"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@lango-project/lango-server": "^0.2.4",
|
|
57
|
+
"cron-parser": "5.10.7",
|
|
58
|
+
"pg-boss": "12.40.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@lango-project/lango-js": "^0.2.0",
|
|
62
|
+
"pg": "^8.23.1"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/boss.lango
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import "./configuration"
|
|
2
|
+
loadConfiguration(directory)
|
|
3
|
+
import "./driver"
|
|
4
|
+
createDriver(config, consumer = false, scheduling = false, cronMonitorIntervalSeconds = 30)
|
|
5
|
+
prepareQueues(driver, targets)
|
|
6
|
+
queueProvider(config)
|
|
7
|
+
import js "@lango-project/lango-server" as server
|
|
8
|
+
import "./management"
|
|
9
|
+
prepareManagement(config)
|
|
10
|
+
import js global Promise
|
|
11
|
+
import js global Object
|
|
12
|
+
|
|
13
|
+
export class Boss(directory)
|
|
14
|
+
methods
|
|
15
|
+
start()
|
|
16
|
+
close()
|
|
17
|
+
configure(builder)
|
|
18
|
+
executor(settings)
|
|
19
|
+
|
|
20
|
+
Boss(directory)
|
|
21
|
+
@config = loadConfiguration(directory)
|
|
22
|
+
@state = "new"
|
|
23
|
+
@driver = null
|
|
24
|
+
@starting = null
|
|
25
|
+
@closing = null
|
|
26
|
+
|
|
27
|
+
Boss:start()
|
|
28
|
+
if @state != "new"
|
|
29
|
+
return Promise/reject("Boss can only be started once")
|
|
30
|
+
@state = "starting"
|
|
31
|
+
@driver = createDriver(@config)
|
|
32
|
+
@starting = prepare()
|
|
33
|
+
return @starting
|
|
34
|
+
|
|
35
|
+
Boss:prepare()
|
|
36
|
+
return chain @driver.start()
|
|
37
|
+
then(ignored)
|
|
38
|
+
return prepareQueues(@driver, @config.targets)
|
|
39
|
+
then(ignored)
|
|
40
|
+
return prepareManagement(@config)
|
|
41
|
+
then(ignored)
|
|
42
|
+
if @state != "starting"
|
|
43
|
+
throw "Boss closed during startup"
|
|
44
|
+
@state = "running"
|
|
45
|
+
return null
|
|
46
|
+
catch(error)
|
|
47
|
+
return chain @driver.stop()
|
|
48
|
+
then(ignored)
|
|
49
|
+
capture error
|
|
50
|
+
@state = "closed"
|
|
51
|
+
throw error
|
|
52
|
+
|
|
53
|
+
Boss:provider()
|
|
54
|
+
return queueProvider(@config)
|
|
55
|
+
|
|
56
|
+
Boss:configure(builder)
|
|
57
|
+
if @state != "running"
|
|
58
|
+
throw "Start Boss before configuring queue submission"
|
|
59
|
+
builder.provideQueue(provider())
|
|
60
|
+
return builder
|
|
61
|
+
|
|
62
|
+
Boss:executor(settings)
|
|
63
|
+
if @state != "running"
|
|
64
|
+
throw "Start Boss before creating an executor"
|
|
65
|
+
if settings == null or !is_object(settings) or is_array(settings) or settings.queueProvider != null
|
|
66
|
+
throw "Executor requires settings without a separate queue provider"
|
|
67
|
+
options = Object/assign({}, settings, {
|
|
68
|
+
queueProvider: provider()
|
|
69
|
+
})
|
|
70
|
+
return new server/Executor(@config.root, options)
|
|
71
|
+
|
|
72
|
+
Boss:close()
|
|
73
|
+
if @closing != null
|
|
74
|
+
return @closing
|
|
75
|
+
if @state == "new" or @state == "closed"
|
|
76
|
+
@state = "closed"
|
|
77
|
+
return Promise/resolve(null)
|
|
78
|
+
@state = "closing"
|
|
79
|
+
pending = Promise/resolve(null)
|
|
80
|
+
if @starting != null
|
|
81
|
+
pending = @starting
|
|
82
|
+
@closing = closeAfter(pending)
|
|
83
|
+
return @closing
|
|
84
|
+
|
|
85
|
+
Boss:closeAfter(pending)
|
|
86
|
+
return chain pending
|
|
87
|
+
catch(error)
|
|
88
|
+
return null
|
|
89
|
+
then(ignored)
|
|
90
|
+
return @driver.stop()
|
|
91
|
+
finally
|
|
92
|
+
@state = "closed"
|