@chidchanun/bcp 0.2.6 → 0.2.8
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/README.md +112 -60
- package/docs/README.md +44 -57
- package/docs/api-manifest.json +23 -1
- package/docs/api-reference.md +67 -0
- package/docs/background-jobs.md +356 -0
- package/docs/development-logging.md +44 -1
- package/docs/docs-web-manifest.json +8 -4
- package/docs/observability.md +445 -0
- package/docs/platform-manifest.json +20 -4
- package/docs/releases/0.2.7.md +205 -0
- package/docs/releases/0.2.8.md +150 -0
- package/package.json +11 -1
- package/packages/bundler/src/client-boundary.ts +2 -0
- package/packages/client/src/jobs.ts +16 -0
- package/packages/client/src/observability.ts +22 -0
- package/packages/server/src/jobs.ts +822 -0
- package/packages/server/src/observability.ts +1258 -0
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# BCP Framework
|
|
2
2
|
|
|
3
|
-
BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, validation, uploads, storage and standalone Node.js production deployment.
|
|
3
|
+
BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, background jobs, observability, validation, uploads, storage and standalone Node.js production deployment.
|
|
4
4
|
|
|
5
|
-
> **Development target:** `0.2.
|
|
5
|
+
> **Development target:** `0.2.8 — Background Jobs Platform`
|
|
6
6
|
>
|
|
7
|
-
> `0.2.
|
|
7
|
+
> `0.2.8` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
|
|
8
8
|
|
|
9
9
|
## 0.2 platform
|
|
10
10
|
|
|
11
|
-
`0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2,
|
|
11
|
+
`0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2, `0.2.6` added Authorization & Security v2, `0.2.7` added Observability Platform v2, and `0.2.8` adds a provider-neutral background-job queue/worker contract with delayed work, retry/backoff, cancellation and process-local reference storage.
|
|
12
12
|
|
|
13
13
|
Machine-readable platform contracts:
|
|
14
14
|
|
|
@@ -35,10 +35,11 @@ docs/api-manifest.json
|
|
|
35
35
|
| Authorization | Auth/guest/role/permission route guards, flat permissions and resource-aware policies |
|
|
36
36
|
| Request security | Same-origin validation and signed CSRF tokens for unsafe mutations |
|
|
37
37
|
| Middleware | Middleware System v2 with onion execution |
|
|
38
|
+
| Background jobs | Adapter contract, in-memory queue, delayed jobs, retries/backoff, cancellation and concurrent workers |
|
|
39
|
+
| Observability | Structured logs, counters/gauges/histograms, Prometheus output, request metrics and health/readiness checks |
|
|
38
40
|
| Validation | Typed validators and structured validation errors |
|
|
39
41
|
| Error handling | HTTP error helpers and consistent error responses |
|
|
40
42
|
| Database | Provider-neutral MySQL, PostgreSQL and SQLite adapters, transactions, lifecycle and migrations |
|
|
41
|
-
| Logging | Structured logger, request logger and request IDs |
|
|
42
43
|
| Uploads | Buffered multipart helpers and production multipart streaming |
|
|
43
44
|
| Storage | Local + S3-compatible storage, streaming, list/copy/move, metadata, bulk delete and signed URLs |
|
|
44
45
|
| Caching | Response cache and revalidation primitives |
|
|
@@ -242,8 +243,6 @@ Read more:
|
|
|
242
243
|
|
|
243
244
|
## Authorization & Security v2 — 0.2.6
|
|
244
245
|
|
|
245
|
-
### Permissions
|
|
246
|
-
|
|
247
246
|
Use flat permissions directly from `bcp/auth`:
|
|
248
247
|
|
|
249
248
|
```ts
|
|
@@ -268,24 +267,7 @@ await requirePermission(
|
|
|
268
267
|
);
|
|
269
268
|
```
|
|
270
269
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
```ts
|
|
274
|
-
import {
|
|
275
|
-
createPermissionGuard,
|
|
276
|
-
} from "bcp/auth";
|
|
277
|
-
|
|
278
|
-
export const guard =
|
|
279
|
-
createPermissionGuard(
|
|
280
|
-
"admin.access"
|
|
281
|
-
);
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
The default permission field is `permissions`. Applications can select another field such as `scopes`.
|
|
285
|
-
|
|
286
|
-
### Resource policies
|
|
287
|
-
|
|
288
|
-
For ownership, tenant or resource-state rules:
|
|
270
|
+
Resource-aware policies:
|
|
289
271
|
|
|
290
272
|
```ts
|
|
291
273
|
import {
|
|
@@ -312,17 +294,6 @@ await authorize(
|
|
|
312
294
|
);
|
|
313
295
|
```
|
|
314
296
|
|
|
315
|
-
Available policy helpers:
|
|
316
|
-
|
|
317
|
-
```text
|
|
318
|
-
can()
|
|
319
|
-
cannot()
|
|
320
|
-
authorize()
|
|
321
|
-
AuthorizationError
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Same-origin and CSRF protection
|
|
325
|
-
|
|
326
297
|
Request-security helpers are exposed from `bcp/server`:
|
|
327
298
|
|
|
328
299
|
```ts
|
|
@@ -333,43 +304,117 @@ import {
|
|
|
333
304
|
} from "bcp/server";
|
|
334
305
|
```
|
|
335
306
|
|
|
336
|
-
|
|
307
|
+
Read more: [Authorization & Security v2](docs/authorization-security.md)
|
|
308
|
+
|
|
309
|
+
## Observability Platform v2 — 0.2.7
|
|
310
|
+
|
|
311
|
+
Create one application metrics registry:
|
|
337
312
|
|
|
338
313
|
```ts
|
|
339
|
-
|
|
314
|
+
import {
|
|
315
|
+
createMetricsRegistry,
|
|
316
|
+
} from "bcp/observability";
|
|
317
|
+
|
|
318
|
+
export const metrics =
|
|
319
|
+
createMetricsRegistry();
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Supported metric types:
|
|
323
|
+
|
|
324
|
+
```text
|
|
325
|
+
counter
|
|
326
|
+
gauge
|
|
327
|
+
histogram
|
|
340
328
|
```
|
|
341
329
|
|
|
342
|
-
|
|
330
|
+
Expose Prometheus-compatible text:
|
|
343
331
|
|
|
344
332
|
```ts
|
|
345
|
-
|
|
346
|
-
|
|
333
|
+
import {
|
|
334
|
+
createMetricsResponse,
|
|
335
|
+
} from "bcp/observability";
|
|
336
|
+
|
|
337
|
+
export function GET() {
|
|
338
|
+
return createMetricsResponse(
|
|
339
|
+
metrics
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
```
|
|
347
343
|
|
|
348
|
-
|
|
344
|
+
Health/readiness registry:
|
|
349
345
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
346
|
+
```ts
|
|
347
|
+
import {
|
|
348
|
+
createHealthRegistry,
|
|
349
|
+
} from "bcp/observability";
|
|
350
|
+
|
|
351
|
+
export const health =
|
|
352
|
+
createHealthRegistry();
|
|
353
353
|
```
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
Read more: [Observability Platform v2](docs/observability.md)
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
## Background Jobs Platform — 0.2.8
|
|
358
|
+
|
|
359
|
+
Create a server-side queue:
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
import {
|
|
363
|
+
createJobQueue,
|
|
364
|
+
} from "bcp/jobs";
|
|
365
|
+
|
|
366
|
+
export const jobs =
|
|
367
|
+
createJobQueue();
|
|
360
368
|
```
|
|
361
369
|
|
|
362
|
-
|
|
370
|
+
Register a handler:
|
|
363
371
|
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
372
|
+
```ts
|
|
373
|
+
jobs.register<{
|
|
374
|
+
userId: number;
|
|
375
|
+
}>(
|
|
376
|
+
"email.welcome",
|
|
377
|
+
async ({ payload }) => {
|
|
378
|
+
await sendWelcomeEmail(
|
|
379
|
+
payload.userId
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
);
|
|
370
383
|
```
|
|
371
384
|
|
|
372
|
-
|
|
385
|
+
Enqueue immediately or with a delay:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
await jobs.enqueue(
|
|
389
|
+
"email.welcome",
|
|
390
|
+
{
|
|
391
|
+
userId: 42,
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
delayMs: 5_000,
|
|
395
|
+
maxAttempts: 5,
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Start concurrent workers:
|
|
401
|
+
|
|
402
|
+
```ts
|
|
403
|
+
const worker =
|
|
404
|
+
jobs.startWorker({
|
|
405
|
+
concurrency: 4,
|
|
406
|
+
pollIntervalMs: 250,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// graceful shutdown
|
|
410
|
+
await worker.stop();
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
The default in-memory adapter is process-local and is intended for development/tests/prototypes. Durable multi-process deployments should implement `JobQueueAdapter` against shared infrastructure. Adapter `reserve()` must atomically claim work.
|
|
414
|
+
|
|
415
|
+
Retry behavior is configurable with fixed or callback-based backoff. The default is capped exponential backoff. Jobs can also be cancelled and inspected with `get()` / `list()`.
|
|
416
|
+
|
|
417
|
+
Read more: [Background Jobs Platform](docs/background-jobs.md)
|
|
373
418
|
|
|
374
419
|
## Public entrypoints
|
|
375
420
|
|
|
@@ -384,6 +429,8 @@ bcp/validation
|
|
|
384
429
|
bcp/error
|
|
385
430
|
bcp/database
|
|
386
431
|
bcp/auth
|
|
432
|
+
bcp/jobs
|
|
433
|
+
bcp/observability
|
|
387
434
|
bcp/server
|
|
388
435
|
bcp/server-only
|
|
389
436
|
bcp/middleware
|
|
@@ -446,6 +493,9 @@ Loader / action / API route
|
|
|
446
493
|
React SSR
|
|
447
494
|
↓
|
|
448
495
|
Hydration / SPA navigation
|
|
496
|
+
|
|
497
|
+
Operational side channels:
|
|
498
|
+
background jobs + structured logs + metrics + health/readiness
|
|
449
499
|
```
|
|
450
500
|
|
|
451
501
|
## Production build
|
|
@@ -491,7 +541,7 @@ npm run test:e2e
|
|
|
491
541
|
npm run rc:check
|
|
492
542
|
```
|
|
493
543
|
|
|
494
|
-
`0.2.
|
|
544
|
+
`0.2.8` adds Background Jobs Platform unit and prepared-package smoke checks covering delayed work, retries/backoff, cancellation, worker concurrency, server-only boundaries and the public `bcp/jobs` package surface.
|
|
495
545
|
|
|
496
546
|
Do not tag or publish until the final release commit passes the complete RC sequence.
|
|
497
547
|
|
|
@@ -512,12 +562,14 @@ Do not tag or publish until the final release commit passes the complete RC sequ
|
|
|
512
562
|
| `0.2.4` | Application Packaging |
|
|
513
563
|
| `0.2.5` | Authentication Platform v2 |
|
|
514
564
|
| `0.2.6` | Authorization & Security v2 |
|
|
565
|
+
| `0.2.7` | Observability Platform v2 |
|
|
566
|
+
| `0.2.8` | Background Jobs Platform |
|
|
515
567
|
|
|
516
568
|
## Roadmap
|
|
517
569
|
|
|
518
|
-
`0.2.
|
|
570
|
+
`0.2.8 — Background Jobs Platform` establishes a provider-neutral queue/worker contract on top of the existing server runtime and lifecycle model.
|
|
519
571
|
|
|
520
|
-
|
|
572
|
+
Later `0.2.x` work can add durable queue providers, recurring schedules, distributed leases or workflow orchestration without changing the base enqueue/worker contract. Native `.exe`, desktop and mobile compilation remain later roadmap work.
|
|
521
573
|
|
|
522
574
|
## License
|
|
523
575
|
|
package/docs/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
|
|
4
4
|
|
|
5
|
-
> **Documentation target:** BCP Framework `0.2.
|
|
5
|
+
> **Documentation target:** BCP Framework `0.2.8 — Background Jobs Platform`
|
|
6
6
|
>
|
|
7
7
|
> **Release state:** unreleased development target until RC validation, tagging and npm publication complete.
|
|
8
8
|
|
|
@@ -52,66 +52,51 @@ Framework source and tests remain authoritative for runtime behavior.
|
|
|
52
52
|
| `0.2.4` | Application Packaging |
|
|
53
53
|
| `0.2.5` | Authentication Platform v2 |
|
|
54
54
|
| `0.2.6` | Authorization & Security v2 |
|
|
55
|
+
| `0.2.7` | Observability Platform v2 |
|
|
56
|
+
| `0.2.8` | Background Jobs Platform |
|
|
55
57
|
|
|
56
|
-
## 0.2.
|
|
58
|
+
## 0.2.8 — Background Jobs Platform
|
|
57
59
|
|
|
58
|
-
`0.2.
|
|
60
|
+
`0.2.8` adds a server-only provider-neutral queue/worker layer without adding a third-party queue dependency.
|
|
59
61
|
|
|
60
62
|
New/updated documentation sources:
|
|
61
63
|
|
|
62
64
|
| Source | Purpose |
|
|
63
65
|
| --- | --- |
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `releases/0.2.
|
|
66
|
+
| `background-jobs.md` | Queue contract, memory adapter, delay, retries, workers and production guidance |
|
|
67
|
+
| `api-reference.md` | Public `bcp/jobs` exports |
|
|
68
|
+
| `platform-manifest.json` | Background Jobs capability flags and public entrypoint |
|
|
69
|
+
| `api-manifest.json` | `bcp/jobs` guide ownership |
|
|
70
|
+
| `docs-web-manifest.json` | Background Jobs navigation and `0.2.8` release route |
|
|
71
|
+
| `releases/0.2.8.md` | Background Jobs Platform release notes |
|
|
70
72
|
|
|
71
|
-
Primary
|
|
73
|
+
Primary APIs:
|
|
72
74
|
|
|
73
75
|
```ts
|
|
74
76
|
import {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
defineAuthorizationPolicy,
|
|
79
|
-
hasPermission,
|
|
80
|
-
requirePermission,
|
|
81
|
-
} from "bcp/auth";
|
|
77
|
+
createJobQueue,
|
|
78
|
+
createMemoryJobQueueAdapter,
|
|
79
|
+
} from "bcp/jobs";
|
|
82
80
|
```
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
import {
|
|
88
|
-
createCsrfToken,
|
|
89
|
-
requireCsrfRequest,
|
|
90
|
-
requireSameOriginRequest,
|
|
91
|
-
} from "bcp/server";
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Security model
|
|
95
|
-
|
|
96
|
-
The `0.2.6` server model separates concerns:
|
|
82
|
+
Runtime model:
|
|
97
83
|
|
|
98
84
|
```text
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
85
|
+
web/API/action
|
|
86
|
+
|
|
|
87
|
+
| enqueue
|
|
88
|
+
v
|
|
89
|
+
JobQueueAdapter
|
|
90
|
+
|
|
|
91
|
+
v
|
|
92
|
+
worker loop(s)
|
|
93
|
+
|
|
|
94
|
+
+-> success
|
|
95
|
+
+-> retry/backoff
|
|
96
|
+
+-> failed/cancelled
|
|
110
97
|
```
|
|
111
98
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
CSRF tokens use `BCP_CSRF_SECRET` when configured and otherwise fall back to `BCP_SESSION_SECRET`. Security secrets must contain at least 32 UTF-8 bytes.
|
|
99
|
+
The built-in memory adapter is process-local and not durable. Multi-process/container production deployments should implement `JobQueueAdapter` against shared durable infrastructure.
|
|
115
100
|
|
|
116
101
|
## Update rule
|
|
117
102
|
|
|
@@ -150,13 +135,14 @@ Important current routes:
|
|
|
150
135
|
| Website route | Markdown source |
|
|
151
136
|
| --- | --- |
|
|
152
137
|
| `/docs/authentication` | `authentication.md` |
|
|
153
|
-
| `/docs/auth-session-store` | `auth-session-store.md` |
|
|
154
|
-
| `/docs/auth-route-guards` | `auth-route-guards.md` |
|
|
155
138
|
| `/docs/authorization-security` | `authorization-security.md` |
|
|
139
|
+
| `/docs/observability` | `observability.md` |
|
|
140
|
+
| `/docs/background-jobs` | `background-jobs.md` |
|
|
141
|
+
| `/docs/development-logging` | `development-logging.md` |
|
|
156
142
|
| `/docs/application-packaging` | `application-packaging.md` |
|
|
157
143
|
| `/docs/database` | `database.md` |
|
|
158
144
|
| `/docs/api-reference` | `api-reference.md` |
|
|
159
|
-
| `/releases/0.2.
|
|
145
|
+
| `/releases/0.2.8` | `releases/0.2.8.md` |
|
|
160
146
|
|
|
161
147
|
Every route/source pair is validated by unit tests.
|
|
162
148
|
|
|
@@ -196,6 +182,8 @@ bcp/validation
|
|
|
196
182
|
bcp/error
|
|
197
183
|
bcp/database
|
|
198
184
|
bcp/auth
|
|
185
|
+
bcp/jobs
|
|
186
|
+
bcp/observability
|
|
199
187
|
bcp/server
|
|
200
188
|
bcp/server-only
|
|
201
189
|
bcp/middleware
|
|
@@ -235,7 +223,7 @@ synchronize CMS/search/navigation
|
|
|
235
223
|
|
|
236
224
|
## Release validation
|
|
237
225
|
|
|
238
|
-
Before publishing `0.2.
|
|
226
|
+
Before publishing `0.2.8`:
|
|
239
227
|
|
|
240
228
|
```bash
|
|
241
229
|
npm run typecheck
|
|
@@ -246,16 +234,15 @@ npm run test:e2e
|
|
|
246
234
|
npm run rc:check
|
|
247
235
|
```
|
|
248
236
|
|
|
249
|
-
|
|
237
|
+
Background Jobs Platform validation covers:
|
|
250
238
|
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
-
|
|
254
|
-
-
|
|
255
|
-
-
|
|
256
|
-
-
|
|
257
|
-
-
|
|
258
|
-
- public `bcp/auth` and `bcp/server` exports,
|
|
239
|
+
- immediate and delayed jobs,
|
|
240
|
+
- retry/backoff behavior,
|
|
241
|
+
- terminal success/failure/cancellation states,
|
|
242
|
+
- duplicate job IDs,
|
|
243
|
+
- worker concurrency and graceful stop,
|
|
244
|
+
- public `bcp/jobs` exports,
|
|
245
|
+
- server-only browser/client boundaries,
|
|
259
246
|
- prepared npm package contents,
|
|
260
247
|
- docs/platform/API version parity.
|
|
261
248
|
|
package/docs/api-manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"framework": "bcp",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.8",
|
|
5
5
|
"releaseState": "unreleased",
|
|
6
6
|
"coverage": "public-entrypoints",
|
|
7
7
|
"entrypoints": [
|
|
@@ -94,6 +94,28 @@
|
|
|
94
94
|
"/docs/session-auth"
|
|
95
95
|
]
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
"package": "bcp/jobs",
|
|
99
|
+
"source": "packages/client/src/jobs.ts",
|
|
100
|
+
"environment": "server",
|
|
101
|
+
"route": "/docs/api-reference#bcp-jobs",
|
|
102
|
+
"summary": "Background job queue contract with in-memory adapter, delayed jobs, retry/backoff, cancellation and concurrent workers.",
|
|
103
|
+
"guides": [
|
|
104
|
+
"/docs/background-jobs",
|
|
105
|
+
"/docs/observability"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"package": "bcp/observability",
|
|
110
|
+
"source": "packages/client/src/observability.ts",
|
|
111
|
+
"environment": "server",
|
|
112
|
+
"route": "/docs/api-reference#bcp-observability",
|
|
113
|
+
"summary": "In-process metrics, Prometheus exposition, request metrics middleware and health/readiness checks.",
|
|
114
|
+
"guides": [
|
|
115
|
+
"/docs/observability",
|
|
116
|
+
"/docs/development-logging"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
97
119
|
{
|
|
98
120
|
"package": "bcp/server",
|
|
99
121
|
"source": "packages/client/src/server.ts",
|
package/docs/api-reference.md
CHANGED
|
@@ -226,6 +226,73 @@ Authorization & Security v2 adds permission checks, permission route guards and
|
|
|
226
226
|
|
|
227
227
|
Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md).
|
|
228
228
|
|
|
229
|
+
## `bcp/jobs`
|
|
230
|
+
|
|
231
|
+
Server-only Background Jobs Platform APIs.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import {
|
|
235
|
+
createJobQueue,
|
|
236
|
+
createMemoryJobQueueAdapter,
|
|
237
|
+
type BackgroundJobQueue,
|
|
238
|
+
type EnqueueJobOptions,
|
|
239
|
+
type JobHandler,
|
|
240
|
+
type JobHandlerContext,
|
|
241
|
+
type JobQueueAdapter,
|
|
242
|
+
type JobQueueOptions,
|
|
243
|
+
type JobRecord,
|
|
244
|
+
type JobRetryDelay,
|
|
245
|
+
type JobState,
|
|
246
|
+
type JobWorker,
|
|
247
|
+
type MemoryJobQueueAdapter,
|
|
248
|
+
type StartJobWorkerOptions,
|
|
249
|
+
} from "bcp/jobs";
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`createJobQueue()` provides delayed enqueueing, retry/backoff, cancellation, manual `processNext()` execution and concurrent workers. The default adapter is process-local memory storage and is intended for development, tests and single-process prototypes.
|
|
253
|
+
|
|
254
|
+
Production applications that require durable processing should implement `JobQueueAdapter` against shared infrastructure. Adapter `reserve()` must atomically claim one eligible queued job so multiple workers cannot process the same reservation concurrently.
|
|
255
|
+
|
|
256
|
+
The queue contract is designed for practical at-least-once processing; handlers should be idempotent when duplicate side effects are unsafe.
|
|
257
|
+
|
|
258
|
+
Related guides: [Background Jobs Platform](background-jobs.md), [Observability Platform v2](observability.md).
|
|
259
|
+
|
|
260
|
+
## `bcp/observability`
|
|
261
|
+
|
|
262
|
+
Server-only Observability Platform v2 APIs.
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
import {
|
|
266
|
+
createHealthRegistry,
|
|
267
|
+
createMetricsRegistry,
|
|
268
|
+
createMetricsResponse,
|
|
269
|
+
createRequestMetricsMiddleware,
|
|
270
|
+
type CounterMetric,
|
|
271
|
+
type GaugeMetric,
|
|
272
|
+
type HealthCheck,
|
|
273
|
+
type HealthCheckOptions,
|
|
274
|
+
type HealthCheckReportItem,
|
|
275
|
+
type HealthCheckResult,
|
|
276
|
+
type HealthRegistry,
|
|
277
|
+
type HealthReport,
|
|
278
|
+
type HistogramMetric,
|
|
279
|
+
type HistogramOptions,
|
|
280
|
+
type MetricDefinitionOptions,
|
|
281
|
+
type MetricLabels,
|
|
282
|
+
type MetricLabelValue,
|
|
283
|
+
type MetricsRegistry,
|
|
284
|
+
type RequestMetricsOptions,
|
|
285
|
+
} from "bcp/observability";
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
`createMetricsRegistry()` provides process-local counters, gauges and histograms. `createMetricsResponse()` renders Prometheus-compatible text exposition. `createRequestMetricsMiddleware()` measures HTTP request counts and duration using bounded `method` / `status` labels by default and intentionally does not label by raw path.
|
|
289
|
+
|
|
290
|
+
`createHealthRegistry()` registers synchronous or asynchronous liveness/readiness checks, applies per-check timeouts and produces JSON health responses with HTTP `200` when all checks pass or `503` when any check fails.
|
|
291
|
+
|
|
292
|
+
The built-in registry is process-local. Multi-instance deployments should scrape each process/container or aggregate through external monitoring infrastructure.
|
|
293
|
+
|
|
294
|
+
Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
|
|
295
|
+
|
|
229
296
|
## `bcp/server`
|
|
230
297
|
|
|
231
298
|
Server request/runtime APIs.
|