@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,118 @@
|
|
|
1
|
+
# Reports example
|
|
2
|
+
|
|
3
|
+
A small loopback JSON service demonstrates the complete Boss path:
|
|
4
|
+
|
|
5
|
+
1. Server assigns a browser/client identity during Register and the application records its observed IP/User-Agent.
|
|
6
|
+
2. The client can submit up to three reports per minute and read only its own job results.
|
|
7
|
+
3. A separate Boss worker resolves live client authority and processes the queue.
|
|
8
|
+
4. `jobs.xml` creates a report every minute under the explicit `job_user` system profile.
|
|
9
|
+
5. A local operator CLI performs authorized reads, retry/cancel, pause/resume, and transactional auditing.
|
|
10
|
+
|
|
11
|
+
This example deliberately has no login endpoint. HTTP clients are anonymous user sources with a limited `reports` capability. `userId` and `grantId` are not fabricated, and no identity or system profile is accepted from request input. For authenticated users, connect the identity provider to the application's real user/grant service, as in Lango Server's security example. `operator` is a trusted local-host tool with database access, not a public administrative HTTP route.
|
|
12
|
+
|
|
13
|
+
## Install and copy
|
|
14
|
+
|
|
15
|
+
Requires Node.js 24+, PostgreSQL, Lango Boss 0.1.0, and Lango Server 0.2.4+. Use a dedicated development database: setup creates `boss_demo_clients` and `boss_demo_reports`, and Boss creates its application-specific schema.
|
|
16
|
+
|
|
17
|
+
After the packages have been published:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
mkdir reports-demo
|
|
21
|
+
cd reports-demo
|
|
22
|
+
npm install @lango-project/lango-boss@0.1.0 @lango-project/lango-server@^0.2.4
|
|
23
|
+
cp -R node_modules/@lango-project/lango-boss/examples/reports ./app
|
|
24
|
+
cd app
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
In PowerShell, use `Copy-Item node_modules/@lango-project/lango-boss/examples/reports app -Recurse` instead of `cp -R`.
|
|
28
|
+
|
|
29
|
+
The package includes `dist/`; running this copied example does not require the Lango compiler. Runtime packages resolve from the parent installation. To edit and rebuild its Lango sources later, run `npm install` and `npm run build` inside `app` to install the development compiler there. Before publication, use the tested local archives described in the [release guide](../../docs/release.md).
|
|
30
|
+
|
|
31
|
+
## Configure and initialize
|
|
32
|
+
|
|
33
|
+
In each terminal, provide the same database URL. The HTTP process also needs a random signing key; do not use a fixed example key:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
export BOSS_DEMO_DATABASE_URL='postgresql://user:password@127.0.0.1/reports_demo'
|
|
37
|
+
export BOSS_DEMO_JWT_KEY="$(openssl rand -hex 32)"
|
|
38
|
+
npm run setup
|
|
39
|
+
npm start
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
PowerShell environment variables use `$env:BOSS_DEMO_DATABASE_URL = '...'` and `$env:BOSS_DEMO_JWT_KEY = '...'`; supply a securely generated key of at least 32 characters.
|
|
43
|
+
|
|
44
|
+
The service binds `127.0.0.1:3000`, as configured in `deploy.xml`. Setup is idempotent and does not erase existing reports or client state. Keep the application's package name stable because it determines Boss's schema.
|
|
45
|
+
|
|
46
|
+
In a second terminal, from the same `app` directory, set `BOSS_DEMO_DATABASE_URL` and run:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm run worker
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The worker and operator do not need `BOSS_DEMO_JWT_KEY`; they use HTTP-free execution. HTTP signing credentials can remain with the HTTP process.
|
|
53
|
+
|
|
54
|
+
## Submit and inspect
|
|
55
|
+
|
|
56
|
+
Open a client identity and copy the `x-lango-token` response header:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
curl -i http://127.0.0.1:3000/whoami \
|
|
60
|
+
-H 'Content-Type: application/json' -d '{}'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then use that exact token for submission and polling:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
export TOKEN='the-x-lango-token-value'
|
|
67
|
+
curl http://127.0.0.1:3000/submit \
|
|
68
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
69
|
+
-H 'Content-Type: application/json' \
|
|
70
|
+
-d '{"message":"Hello from the queue"}'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The response is `{ "jobId": "..." }`. Read it with:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
curl http://127.0.0.1:3000/status \
|
|
77
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
78
|
+
-H 'Content-Type: application/json' \
|
|
79
|
+
-d '{"jobId":"the-returned-id"}'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
When completed, `resultAvailable` is true and `result` contains the message and the original client ID. A different client, including a request without the original token, sees null for this job. If a response supplies a newer `x-lango-token`, retain it for subsequent calls. There is no automatic retry of HTTP submissions.
|
|
83
|
+
|
|
84
|
+
The fourth submission in a minute returns `429 SubmissionLimit`; invalid/overlong messages return `400`. Every request and execution attempt checks the current client row. Setting `banned=true` or `can_submit=false` in `boss_demo_clients` rejects further HTTP access and prevents that client's queued work from executing.
|
|
85
|
+
|
|
86
|
+
## Operator workflow
|
|
87
|
+
|
|
88
|
+
In another local terminal, set only `BOSS_DEMO_DATABASE_URL`:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
npm run operator -- jobs
|
|
92
|
+
npm run operator -- job JOB_ID
|
|
93
|
+
npm run operator -- queues
|
|
94
|
+
npm run operator -- schedules
|
|
95
|
+
npm run operator -- pauseQueue reports
|
|
96
|
+
npm run operator -- resumeQueue reports
|
|
97
|
+
npm run operator -- pauseSchedule minute-report
|
|
98
|
+
npm run operator -- resumeSchedule minute-report
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
To demonstrate manual retry, submit `{ "message": "Retry me", "failOnce": true }`. The first attempt rejects permanently with `DemoFailure`; it does not consume automatic retries. Then run:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
npm run operator -- retry JOB_ID
|
|
105
|
+
npm run operator -- job JOB_ID
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The next attempt runs under the original client, not `operator`. This system profile has only `boss.manage`, while `job_user` has only `reports`. The shared identity function defines both profiles explicitly.
|
|
109
|
+
|
|
110
|
+
`npm run operator -- cancel JOB_ID` requests cancellation. Queue pause stops new fetches while submission can continue. Schedule pause does not cancel previously emitted jobs. See the [management guide](../../docs/management.md) for transaction, cancellation timing, and audit semantics. Operations write actor/outcome metadata into the application's `lango_management_audit` table.
|
|
111
|
+
|
|
112
|
+
## Files and transaction boundaries
|
|
113
|
+
|
|
114
|
+
`routes.xml` defines internal jobs; `app.lango` builds the three HTTP endpoints and Register/middleware wiring. `/operator` is an internal target only and is not an HTTP endpoint. `deploy.xml` is shared by producer, worker, setup, and operator.
|
|
115
|
+
|
|
116
|
+
Submission updates its client quota and enqueues in one Lango SQL transaction. Report generation uses the job ID as an idempotency key and commits its report before queue settlement. A replay of the same job cannot insert a second report. Distinct submissions are distinct jobs; no global message deduplication is implied.
|
|
117
|
+
|
|
118
|
+
The published `jobs.xml` uses a one-minute cron. Change its revision when changing effective definitions. The package smoke test accelerates this to second precision only in its isolated test copy.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import js "@lango-project/lango-boss" as boss
|
|
2
|
+
import js "@lango-project/lango-server" as server
|
|
3
|
+
import js "node:path" as path
|
|
4
|
+
import js "node:crypto" as crypto
|
|
5
|
+
import js global process
|
|
6
|
+
import "./setup"
|
|
7
|
+
initialize()
|
|
8
|
+
|
|
9
|
+
export main(args)
|
|
10
|
+
|
|
11
|
+
main(args)
|
|
12
|
+
directory = process.cwd()
|
|
13
|
+
if args.length == 1 and args[0] == "setup"
|
|
14
|
+
return server/withDatabase(directory, initialize)
|
|
15
|
+
if args.length == 1 and args[0] == "server"
|
|
16
|
+
return serve(directory)
|
|
17
|
+
if args.length >= 2 and args[0] == "operator"
|
|
18
|
+
return operate(directory, args)
|
|
19
|
+
throw "Usage: node dist/app.mjs setup|server|operator <action> [target]"
|
|
20
|
+
|
|
21
|
+
serve(directory)
|
|
22
|
+
producer = new boss/Boss(directory)
|
|
23
|
+
state = {
|
|
24
|
+
http: null
|
|
25
|
+
stopping: false
|
|
26
|
+
}
|
|
27
|
+
stop = ()
|
|
28
|
+
capture state
|
|
29
|
+
if state.stopping
|
|
30
|
+
return null
|
|
31
|
+
state.stopping = true
|
|
32
|
+
return chain state.http.close()
|
|
33
|
+
finally
|
|
34
|
+
capture producer
|
|
35
|
+
return producer.close()
|
|
36
|
+
catch(error)
|
|
37
|
+
process.stderr.write("Report server shutdown failed: ${error}\n")
|
|
38
|
+
process.exitCode = 1
|
|
39
|
+
return chain producer.start()
|
|
40
|
+
then(ignored)
|
|
41
|
+
capture producer
|
|
42
|
+
capture state
|
|
43
|
+
capture directory
|
|
44
|
+
builder = new server/Builder(directory)
|
|
45
|
+
builder.loadDeployment()
|
|
46
|
+
builder.addMiddleware("client", {
|
|
47
|
+
module: "./dist/handlers.mjs"
|
|
48
|
+
handler: "guard"
|
|
49
|
+
})
|
|
50
|
+
builder.event({
|
|
51
|
+
name: "register"
|
|
52
|
+
module: "./dist/handlers.mjs"
|
|
53
|
+
handler: "register"
|
|
54
|
+
})
|
|
55
|
+
for ["submit", "status", "whoami"] as handler
|
|
56
|
+
builder.endpoint({
|
|
57
|
+
path: "/${handler}"
|
|
58
|
+
module: "./dist/handlers.mjs"
|
|
59
|
+
handler: handler
|
|
60
|
+
policy: "anonymous"
|
|
61
|
+
middleware: "client"
|
|
62
|
+
})
|
|
63
|
+
producer.configure(builder)
|
|
64
|
+
state.http = builder.build()
|
|
65
|
+
return state.http.start()
|
|
66
|
+
then(address)
|
|
67
|
+
capture stop
|
|
68
|
+
println("Listening on ${address.address}:${address.port}")
|
|
69
|
+
process.once("SIGTERM", stop)
|
|
70
|
+
process.once("SIGINT", stop)
|
|
71
|
+
catch(error)
|
|
72
|
+
capture producer
|
|
73
|
+
return chain producer.close()
|
|
74
|
+
finally
|
|
75
|
+
capture state
|
|
76
|
+
if state.http != null
|
|
77
|
+
return state.http.close()
|
|
78
|
+
return null
|
|
79
|
+
finally
|
|
80
|
+
capture error
|
|
81
|
+
throw error
|
|
82
|
+
|
|
83
|
+
operate(directory, args)
|
|
84
|
+
action = args[1]
|
|
85
|
+
read = ["jobs", "queues", "schedules"]
|
|
86
|
+
changes = ["job", "retry", "cancel", "pauseQueue", "resumeQueue", "pauseSchedule", "resumeSchedule"]
|
|
87
|
+
if (!read.includes(action) and !changes.includes(action)) or args.length > 3
|
|
88
|
+
throw "Unknown operator action"
|
|
89
|
+
if changes.includes(action) and args.length != 3
|
|
90
|
+
throw "Operator action requires a target"
|
|
91
|
+
producer = new boss/Boss(directory)
|
|
92
|
+
state = {
|
|
93
|
+
executor: null
|
|
94
|
+
}
|
|
95
|
+
return chain producer.start()
|
|
96
|
+
then(ignored)
|
|
97
|
+
capture producer
|
|
98
|
+
capture state
|
|
99
|
+
state.executor = producer.executor({
|
|
100
|
+
identity: {
|
|
101
|
+
module: "./dist/handlers.mjs"
|
|
102
|
+
handler: "identity"
|
|
103
|
+
}
|
|
104
|
+
workers: 1
|
|
105
|
+
})
|
|
106
|
+
return state.executor.start()
|
|
107
|
+
then(ignored)
|
|
108
|
+
capture state
|
|
109
|
+
capture args
|
|
110
|
+
capture action
|
|
111
|
+
capture crypto
|
|
112
|
+
return state.executor.execute({
|
|
113
|
+
id: "operator:${crypto/randomUUID()}"
|
|
114
|
+
path: "/operator"
|
|
115
|
+
input: {
|
|
116
|
+
action: action
|
|
117
|
+
target: args[2]
|
|
118
|
+
}
|
|
119
|
+
source: {
|
|
120
|
+
kind: "system"
|
|
121
|
+
identity: "operator"
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
then(result)
|
|
125
|
+
println(to_json(result))
|
|
126
|
+
finally
|
|
127
|
+
capture state
|
|
128
|
+
if state.executor != null
|
|
129
|
+
return state.executor.close()
|
|
130
|
+
return null
|
|
131
|
+
finally
|
|
132
|
+
capture producer
|
|
133
|
+
return producer.close()
|