@chidchanun/bcp 0.2.7 → 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 +62 -35
- package/docs/README.md +38 -35
- package/docs/api-manifest.json +12 -1
- package/docs/api-reference.md +31 -0
- package/docs/background-jobs.md +356 -0
- package/docs/docs-web-manifest.json +5 -3
- package/docs/platform-manifest.json +13 -4
- package/docs/releases/0.2.8.md +150 -0
- package/package.json +6 -1
- package/packages/bundler/src/client-boundary.ts +1 -0
- package/packages/client/src/jobs.ts +16 -0
- package/packages/server/src/jobs.ts +822 -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, observability, 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, `0.2.6` added Authorization & Security 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,6 +35,7 @@ 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 |
|
|
38
39
|
| Observability | Structured logs, counters/gauges/histograms, Prometheus output, request metrics and health/readiness checks |
|
|
39
40
|
| Validation | Typed validators and structured validation errors |
|
|
40
41
|
| Error handling | HTTP error helpers and consistent error responses |
|
|
@@ -340,56 +341,80 @@ export function GET() {
|
|
|
340
341
|
}
|
|
341
342
|
```
|
|
342
343
|
|
|
343
|
-
|
|
344
|
+
Health/readiness registry:
|
|
344
345
|
|
|
345
346
|
```ts
|
|
346
347
|
import {
|
|
347
|
-
|
|
348
|
+
createHealthRegistry,
|
|
348
349
|
} from "bcp/observability";
|
|
349
350
|
|
|
350
|
-
export const
|
|
351
|
-
|
|
352
|
-
metrics
|
|
353
|
-
);
|
|
351
|
+
export const health =
|
|
352
|
+
createHealthRegistry();
|
|
354
353
|
```
|
|
355
354
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
```text
|
|
359
|
-
bcp_http_requests_total{method,status}
|
|
360
|
-
bcp_http_request_duration_seconds{method,status}
|
|
361
|
-
```
|
|
355
|
+
Read more: [Observability Platform v2](docs/observability.md)
|
|
362
356
|
|
|
363
|
-
|
|
357
|
+
## Background Jobs Platform — 0.2.8
|
|
364
358
|
|
|
365
|
-
|
|
359
|
+
Create a server-side queue:
|
|
366
360
|
|
|
367
361
|
```ts
|
|
368
362
|
import {
|
|
369
|
-
|
|
370
|
-
} from "bcp/
|
|
363
|
+
createJobQueue,
|
|
364
|
+
} from "bcp/jobs";
|
|
371
365
|
|
|
372
|
-
export const
|
|
373
|
-
|
|
366
|
+
export const jobs =
|
|
367
|
+
createJobQueue();
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Register a handler:
|
|
374
371
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
372
|
+
```ts
|
|
373
|
+
jobs.register<{
|
|
374
|
+
userId: number;
|
|
375
|
+
}>(
|
|
376
|
+
"email.welcome",
|
|
377
|
+
async ({ payload }) => {
|
|
378
|
+
await sendWelcomeEmail(
|
|
379
|
+
payload.userId
|
|
380
|
+
);
|
|
380
381
|
}
|
|
381
382
|
);
|
|
382
383
|
```
|
|
383
384
|
|
|
384
|
-
|
|
385
|
+
Enqueue immediately or with a delay:
|
|
385
386
|
|
|
386
387
|
```ts
|
|
387
|
-
|
|
388
|
+
await jobs.enqueue(
|
|
389
|
+
"email.welcome",
|
|
390
|
+
{
|
|
391
|
+
userId: 42,
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
delayMs: 5_000,
|
|
395
|
+
maxAttempts: 5,
|
|
396
|
+
}
|
|
397
|
+
);
|
|
388
398
|
```
|
|
389
399
|
|
|
390
|
-
|
|
400
|
+
Start concurrent workers:
|
|
391
401
|
|
|
392
|
-
|
|
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)
|
|
393
418
|
|
|
394
419
|
## Public entrypoints
|
|
395
420
|
|
|
@@ -404,6 +429,7 @@ bcp/validation
|
|
|
404
429
|
bcp/error
|
|
405
430
|
bcp/database
|
|
406
431
|
bcp/auth
|
|
432
|
+
bcp/jobs
|
|
407
433
|
bcp/observability
|
|
408
434
|
bcp/server
|
|
409
435
|
bcp/server-only
|
|
@@ -469,7 +495,7 @@ React SSR
|
|
|
469
495
|
Hydration / SPA navigation
|
|
470
496
|
|
|
471
497
|
Operational side channels:
|
|
472
|
-
structured logs + metrics + health/readiness
|
|
498
|
+
background jobs + structured logs + metrics + health/readiness
|
|
473
499
|
```
|
|
474
500
|
|
|
475
501
|
## Production build
|
|
@@ -515,7 +541,7 @@ npm run test:e2e
|
|
|
515
541
|
npm run rc:check
|
|
516
542
|
```
|
|
517
543
|
|
|
518
|
-
`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.
|
|
519
545
|
|
|
520
546
|
Do not tag or publish until the final release commit passes the complete RC sequence.
|
|
521
547
|
|
|
@@ -537,12 +563,13 @@ Do not tag or publish until the final release commit passes the complete RC sequ
|
|
|
537
563
|
| `0.2.5` | Authentication Platform v2 |
|
|
538
564
|
| `0.2.6` | Authorization & Security v2 |
|
|
539
565
|
| `0.2.7` | Observability Platform v2 |
|
|
566
|
+
| `0.2.8` | Background Jobs Platform |
|
|
540
567
|
|
|
541
568
|
## Roadmap
|
|
542
569
|
|
|
543
|
-
`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.
|
|
544
571
|
|
|
545
|
-
|
|
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.
|
|
546
573
|
|
|
547
574
|
## License
|
|
548
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
|
|
|
@@ -53,48 +53,50 @@ Framework source and tests remain authoritative for runtime behavior.
|
|
|
53
53
|
| `0.2.5` | Authentication Platform v2 |
|
|
54
54
|
| `0.2.6` | Authorization & Security v2 |
|
|
55
55
|
| `0.2.7` | Observability Platform v2 |
|
|
56
|
+
| `0.2.8` | Background Jobs Platform |
|
|
56
57
|
|
|
57
|
-
## 0.2.
|
|
58
|
+
## 0.2.8 — Background Jobs Platform
|
|
58
59
|
|
|
59
|
-
`0.2.
|
|
60
|
+
`0.2.8` adds a server-only provider-neutral queue/worker layer without adding a third-party queue dependency.
|
|
60
61
|
|
|
61
62
|
New/updated documentation sources:
|
|
62
63
|
|
|
63
64
|
| Source | Purpose |
|
|
64
65
|
| --- | --- |
|
|
65
|
-
| `
|
|
66
|
-
| `api-reference.md` | Public `bcp/
|
|
67
|
-
| `platform-manifest.json` |
|
|
68
|
-
| `api-manifest.json` | `bcp/
|
|
69
|
-
| `docs-web-manifest.json` |
|
|
70
|
-
| `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 |
|
|
71
72
|
|
|
72
73
|
Primary APIs:
|
|
73
74
|
|
|
74
75
|
```ts
|
|
75
76
|
import {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
createRequestMetricsMiddleware,
|
|
80
|
-
} from "bcp/observability";
|
|
77
|
+
createJobQueue,
|
|
78
|
+
createMemoryJobQueueAdapter,
|
|
79
|
+
} from "bcp/jobs";
|
|
81
80
|
```
|
|
82
81
|
|
|
83
82
|
Runtime model:
|
|
84
83
|
|
|
85
84
|
```text
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
The
|
|
96
|
-
|
|
97
|
-
The built-in metrics registry is process-local; distributed aggregation remains deployment infrastructure or future exporter work.
|
|
99
|
+
The built-in memory adapter is process-local and not durable. Multi-process/container production deployments should implement `JobQueueAdapter` against shared durable infrastructure.
|
|
98
100
|
|
|
99
101
|
## Update rule
|
|
100
102
|
|
|
@@ -135,11 +137,12 @@ Important current routes:
|
|
|
135
137
|
| `/docs/authentication` | `authentication.md` |
|
|
136
138
|
| `/docs/authorization-security` | `authorization-security.md` |
|
|
137
139
|
| `/docs/observability` | `observability.md` |
|
|
140
|
+
| `/docs/background-jobs` | `background-jobs.md` |
|
|
138
141
|
| `/docs/development-logging` | `development-logging.md` |
|
|
139
142
|
| `/docs/application-packaging` | `application-packaging.md` |
|
|
140
143
|
| `/docs/database` | `database.md` |
|
|
141
144
|
| `/docs/api-reference` | `api-reference.md` |
|
|
142
|
-
| `/releases/0.2.
|
|
145
|
+
| `/releases/0.2.8` | `releases/0.2.8.md` |
|
|
143
146
|
|
|
144
147
|
Every route/source pair is validated by unit tests.
|
|
145
148
|
|
|
@@ -179,6 +182,7 @@ bcp/validation
|
|
|
179
182
|
bcp/error
|
|
180
183
|
bcp/database
|
|
181
184
|
bcp/auth
|
|
185
|
+
bcp/jobs
|
|
182
186
|
bcp/observability
|
|
183
187
|
bcp/server
|
|
184
188
|
bcp/server-only
|
|
@@ -219,7 +223,7 @@ synchronize CMS/search/navigation
|
|
|
219
223
|
|
|
220
224
|
## Release validation
|
|
221
225
|
|
|
222
|
-
Before publishing `0.2.
|
|
226
|
+
Before publishing `0.2.8`:
|
|
223
227
|
|
|
224
228
|
```bash
|
|
225
229
|
npm run typecheck
|
|
@@ -230,16 +234,15 @@ npm run test:e2e
|
|
|
230
234
|
npm run rc:check
|
|
231
235
|
```
|
|
232
236
|
|
|
233
|
-
|
|
237
|
+
Background Jobs Platform validation covers:
|
|
234
238
|
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
-
|
|
238
|
-
-
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
-
|
|
242
|
-
- public `bcp/observability` 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,
|
|
243
246
|
- prepared npm package contents,
|
|
244
247
|
- docs/platform/API version parity.
|
|
245
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,17 @@
|
|
|
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
|
+
},
|
|
97
108
|
{
|
|
98
109
|
"package": "bcp/observability",
|
|
99
110
|
"source": "packages/client/src/observability.ts",
|
package/docs/api-reference.md
CHANGED
|
@@ -226,6 +226,37 @@ 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
|
+
|
|
229
260
|
## `bcp/observability`
|
|
230
261
|
|
|
231
262
|
Server-only Observability Platform v2 APIs.
|