@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# BCP Framework 0.2.8
|
|
2
|
+
|
|
3
|
+
**Milestone:** Background Jobs Platform
|
|
4
|
+
|
|
5
|
+
`0.2.8` adds a framework-native server-side background-job queue contract with a process-local reference adapter, delayed execution, retries/backoff, worker concurrency and cancellation.
|
|
6
|
+
|
|
7
|
+
> Release state: unreleased until the final RC sequence, tag and npm publication complete.
|
|
8
|
+
|
|
9
|
+
## New public entrypoint
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import {
|
|
13
|
+
createJobQueue,
|
|
14
|
+
createMemoryJobQueueAdapter,
|
|
15
|
+
} from "bcp/jobs";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`bcp/jobs` is server-only and is protected by both package browser exports and the BCP client-boundary validator.
|
|
19
|
+
|
|
20
|
+
## Queue adapter contract
|
|
21
|
+
|
|
22
|
+
Applications and ecosystem packages can implement `JobQueueAdapter` for durable/shared infrastructure.
|
|
23
|
+
|
|
24
|
+
The contract covers:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
enqueue
|
|
28
|
+
reserve
|
|
29
|
+
complete
|
|
30
|
+
fail
|
|
31
|
+
cancel
|
|
32
|
+
get
|
|
33
|
+
list
|
|
34
|
+
close (optional)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`reserve()` is the adapter's atomic claim boundary for multi-worker processing.
|
|
38
|
+
|
|
39
|
+
## In-memory reference adapter
|
|
40
|
+
|
|
41
|
+
`createMemoryJobQueueAdapter()` provides a dependency-free process-local adapter for development, tests and prototypes.
|
|
42
|
+
|
|
43
|
+
The memory adapter is intentionally not durable and cannot coordinate multiple Node.js processes or containers.
|
|
44
|
+
|
|
45
|
+
## Delayed jobs
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
await jobs.enqueue(
|
|
49
|
+
"report.generate",
|
|
50
|
+
payload,
|
|
51
|
+
{
|
|
52
|
+
delayMs: 60_000,
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Jobs are eligible for reservation only after `availableAt`.
|
|
58
|
+
|
|
59
|
+
## Retry and backoff
|
|
60
|
+
|
|
61
|
+
Queues default to three maximum attempts and capped exponential retry delay.
|
|
62
|
+
|
|
63
|
+
Applications can configure a fixed delay or callback:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
createJobQueue({
|
|
67
|
+
defaultMaxAttempts: 5,
|
|
68
|
+
retryDelayMs: attempt =>
|
|
69
|
+
attempt * 5_000,
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Per-job `maxAttempts` overrides the queue default.
|
|
74
|
+
|
|
75
|
+
## Workers
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const worker =
|
|
79
|
+
jobs.startWorker({
|
|
80
|
+
concurrency: 4,
|
|
81
|
+
pollIntervalMs: 250,
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Workers run concurrent processing loops and can be stopped gracefully.
|
|
86
|
+
|
|
87
|
+
`jobs.close()` stops all workers started by that queue and closes the adapter when supported.
|
|
88
|
+
|
|
89
|
+
## Cancellation
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
await jobs.cancel(jobId);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Cancelled records remain terminal; later worker completion/failure writes do not overwrite cancellation in the memory adapter.
|
|
96
|
+
|
|
97
|
+
## Manual processing
|
|
98
|
+
|
|
99
|
+
`processNext()` remains available for deterministic tests and custom supervisors.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const processed =
|
|
103
|
+
await jobs.processNext();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Package and platform contracts
|
|
107
|
+
|
|
108
|
+
`0.2.8` adds:
|
|
109
|
+
|
|
110
|
+
- `bcp/jobs` to the framework package export map,
|
|
111
|
+
- TypeScript path mapping for repository development,
|
|
112
|
+
- server-only client-boundary enforcement,
|
|
113
|
+
- Background Jobs capability metadata in `platform-manifest.json`,
|
|
114
|
+
- API-manifest ownership and docs-web navigation,
|
|
115
|
+
- prepared-package smoke coverage.
|
|
116
|
+
|
|
117
|
+
## Compatibility
|
|
118
|
+
|
|
119
|
+
`0.2.8` does not intentionally remove or rename existing `0.2.7` public APIs.
|
|
120
|
+
|
|
121
|
+
Existing applications do not need to adopt background jobs.
|
|
122
|
+
|
|
123
|
+
The built-in queue is opt-in and no additional runtime dependency is installed.
|
|
124
|
+
|
|
125
|
+
## Delivery semantics
|
|
126
|
+
|
|
127
|
+
Durable adapters should be designed for at-least-once processing. Job handlers should be idempotent when duplicate side effects are unsafe.
|
|
128
|
+
|
|
129
|
+
`0.2.8` does not promise exactly-once execution.
|
|
130
|
+
|
|
131
|
+
## Not included
|
|
132
|
+
|
|
133
|
+
This milestone does not ship built-in adapters for Redis, PostgreSQL, SQS, RabbitMQ, Kafka, cron scheduling or workflow orchestration.
|
|
134
|
+
|
|
135
|
+
Those providers/features can be layered behind the new queue contract in later versions.
|
|
136
|
+
|
|
137
|
+
## Validation
|
|
138
|
+
|
|
139
|
+
Before tagging/publishing `0.2.8` run:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm run typecheck
|
|
143
|
+
npm run test:unit
|
|
144
|
+
npm run test:integration
|
|
145
|
+
npm run test:e2e
|
|
146
|
+
npm run test:package
|
|
147
|
+
npm run rc:check
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The final release tag must point to the exact commit that passed the complete RC sequence.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chidchanun/bcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "BCP Framework - a React full-stack framework with file-based routing, SSR, APIs, middleware, islands, caching and standalone production builds.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,6 +62,16 @@
|
|
|
62
62
|
"browser": "./packages/client/src/server-only.browser.mjs",
|
|
63
63
|
"default": "./packages/client/src/auth.ts"
|
|
64
64
|
},
|
|
65
|
+
"./jobs": {
|
|
66
|
+
"types": "./packages/client/src/jobs.ts",
|
|
67
|
+
"browser": "./packages/client/src/server-only.browser.mjs",
|
|
68
|
+
"default": "./packages/client/src/jobs.ts"
|
|
69
|
+
},
|
|
70
|
+
"./observability": {
|
|
71
|
+
"types": "./packages/client/src/observability.ts",
|
|
72
|
+
"browser": "./packages/client/src/server-only.browser.mjs",
|
|
73
|
+
"default": "./packages/client/src/observability.ts"
|
|
74
|
+
},
|
|
65
75
|
"./server": {
|
|
66
76
|
"types": "./packages/client/src/server.ts",
|
|
67
77
|
"browser": "./packages/client/src/server-only.browser.mjs",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createJobQueue,
|
|
3
|
+
createMemoryJobQueueAdapter,
|
|
4
|
+
type BackgroundJobQueue,
|
|
5
|
+
type EnqueueJobOptions,
|
|
6
|
+
type JobHandler,
|
|
7
|
+
type JobHandlerContext,
|
|
8
|
+
type JobQueueAdapter,
|
|
9
|
+
type JobQueueOptions,
|
|
10
|
+
type JobRecord,
|
|
11
|
+
type JobRetryDelay,
|
|
12
|
+
type JobState,
|
|
13
|
+
type JobWorker,
|
|
14
|
+
type MemoryJobQueueAdapter,
|
|
15
|
+
type StartJobWorkerOptions,
|
|
16
|
+
} from "../../server/src/jobs.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createHealthRegistry,
|
|
3
|
+
createMetricsRegistry,
|
|
4
|
+
createMetricsResponse,
|
|
5
|
+
createRequestMetricsMiddleware,
|
|
6
|
+
|
|
7
|
+
type CounterMetric,
|
|
8
|
+
type GaugeMetric,
|
|
9
|
+
type HealthCheck,
|
|
10
|
+
type HealthCheckOptions,
|
|
11
|
+
type HealthCheckReportItem,
|
|
12
|
+
type HealthCheckResult,
|
|
13
|
+
type HealthRegistry,
|
|
14
|
+
type HealthReport,
|
|
15
|
+
type HistogramMetric,
|
|
16
|
+
type HistogramOptions,
|
|
17
|
+
type MetricDefinitionOptions,
|
|
18
|
+
type MetricLabels,
|
|
19
|
+
type MetricLabelValue,
|
|
20
|
+
type MetricsRegistry,
|
|
21
|
+
type RequestMetricsOptions,
|
|
22
|
+
} from "../../server/src/observability.js";
|