@harlan-zw/nuxt-cf-jobs 0.2.0 → 0.2.2
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 +15 -5
- package/dist/module.json +2 -2
- package/dist/module.mjs +1 -1
- package/dist/runtime/server/d1.js +5 -1
- package/dist/runtime/server/outbox.d.ts +3 -1
- package/dist/runtime/server/recovery.js +11 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -27,15 +27,23 @@ Status: experimental. APIs may change before the first scoped release.
|
|
|
27
27
|
- ⏰ **Scheduled tasks:** declare the cron beside the task and generate Nitro and Cloudflare scheduling config from it.
|
|
28
28
|
- 📡 **Realtime progress:** publish job and batch events over Nitro WebSockets and a Durable Object.
|
|
29
29
|
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx nuxi@latest module add @harlan-zw/nuxt-cf-jobs
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> [!TIP]
|
|
37
|
+
> Generate an Agent Skill for this package using [skilld](https://github.com/harlan-zw/skilld):
|
|
38
|
+
> ```bash
|
|
39
|
+
> npx skilld add @harlan-zw/nuxt-cf-jobs
|
|
40
|
+
> ```
|
|
41
|
+
|
|
30
42
|
## Quick start
|
|
31
43
|
|
|
32
44
|
The basic path sends a typed message directly to Cloudflare Queues. D1 is optional and covered under [Durable jobs](#durable-jobs).
|
|
33
45
|
|
|
34
|
-
### 1.
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
pnpm add @harlan-zw/nuxt-cf-jobs
|
|
38
|
-
```
|
|
46
|
+
### 1. Map your queues
|
|
39
47
|
|
|
40
48
|
Map each logical queue name to the binding exposed by Cloudflare:
|
|
41
49
|
|
|
@@ -362,6 +370,8 @@ The generated `prepareJob()` loads the full job definition, validates the payloa
|
|
|
362
370
|
|
|
363
371
|
The module registers `cf-jobs:reconcile` by default. Every two minutes it reclaims stale reservations, re-dispatches older due rows that have no queue message, and closes orphaned batches when it has enough terminal evidence.
|
|
364
372
|
|
|
373
|
+
If a transport message reaches its DLQ during a live reservation, the row becomes unpublished when durable attempts remain. Reconcile sends a replacement as soon as it releases the stale reservation. Rows with exhausted durable attempts become terminal failures instead.
|
|
374
|
+
|
|
365
375
|
```ts
|
|
366
376
|
export default defineNuxtConfig({
|
|
367
377
|
cfJobs: {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -406,7 +406,11 @@ export function createD1DurableJobRepository(db, opts = {}) {
|
|
|
406
406
|
const evidence = dlqArrivalEvidence(at, input.messageAttempts);
|
|
407
407
|
const row = await db.prepare(`
|
|
408
408
|
UPDATE ${jobsTable}
|
|
409
|
-
SET
|
|
409
|
+
SET published_at = CASE
|
|
410
|
+
WHEN max_attempts IS NULL OR attempts < max_attempts THEN NULL
|
|
411
|
+
ELSE published_at
|
|
412
|
+
END,
|
|
413
|
+
retry_reasons = ${appendFailureEvidenceSql("retry_reasons")}
|
|
410
414
|
WHERE id = ?
|
|
411
415
|
AND completed_at IS NULL
|
|
412
416
|
AND failed_at IS NULL
|
|
@@ -138,7 +138,9 @@ export type NoteDurableJobDlqArrivalResult = {
|
|
|
138
138
|
export interface DurableJobFailureEvidenceRepository {
|
|
139
139
|
/**
|
|
140
140
|
* Record that Cloudflare exhausted a durable message while its row could not
|
|
141
|
-
* be claimed.
|
|
141
|
+
* be claimed. Retriable rows become unpublished so recovery can replace the
|
|
142
|
+
* exhausted transport message after releasing its stale reservation. This
|
|
143
|
+
* must not take ownership of the row.
|
|
142
144
|
*/
|
|
143
145
|
noteDlqArrival: (id: string, input: NoteDurableJobDlqArrivalInput) => Promise<NoteDurableJobDlqArrivalResult>;
|
|
144
146
|
}
|
|
@@ -32,16 +32,22 @@ export async function recoverDurableJobs(repository, publisher, opts = {}) {
|
|
|
32
32
|
limit
|
|
33
33
|
});
|
|
34
34
|
const redispatchGraceSeconds = Math.max(0, opts.redispatchGraceSeconds ?? orphanedSeconds);
|
|
35
|
-
const
|
|
35
|
+
const unpublished = await findDispatchableDurableJobs(repository, {
|
|
36
|
+
now: nowSeconds,
|
|
37
|
+
publication: "unpublished",
|
|
38
|
+
limit
|
|
39
|
+
});
|
|
40
|
+
const remainingLimit = Math.max(0, limit - unpublished.length);
|
|
41
|
+
const orphaned = remainingLimit > 0 ? await findDispatchableDurableJobs(repository, {
|
|
36
42
|
now: nowSeconds,
|
|
37
43
|
createdBefore: nowSeconds - orphanedSeconds,
|
|
38
44
|
...redeliveryGraceSeconds > 0 ? { staleReleasedBefore: nowSeconds - redeliveryGraceSeconds } : {},
|
|
39
45
|
...redispatchGraceSeconds > 0 ? { redispatchedBefore: nowSeconds - redispatchGraceSeconds } : {},
|
|
40
|
-
publication: "
|
|
41
|
-
limit
|
|
42
|
-
});
|
|
46
|
+
publication: "published",
|
|
47
|
+
limit: remainingLimit
|
|
48
|
+
}) : [];
|
|
43
49
|
const releasedIds = new Set(stale.slice(0, released).map((job) => job.id));
|
|
44
|
-
const dispatchable = uniqueJobs(redeliveryGraceSeconds > 0 ? orphaned.filter((job) => !releasedIds.has(job.id)) : [...stale.slice(0, released), ...orphaned]);
|
|
50
|
+
const dispatchable = uniqueJobs(redeliveryGraceSeconds > 0 ? [...unpublished, ...orphaned.filter((job) => !releasedIds.has(job.id))] : [...unpublished, ...stale.slice(0, released), ...orphaned]);
|
|
45
51
|
const publicationRepository = repository;
|
|
46
52
|
const dispatchResults = publicationRepository.markJobsPublished && publicationRepository.noteJobsDispatchFailure ? (await publishDurableJobBatch(
|
|
47
53
|
publicationRepository,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harlan-zw/nuxt-cf-jobs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "Experimental Nuxt module for typed Cloudflare queue jobs.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
"peerDependencies": {
|
|
124
124
|
"@sentry/cloudflare": "^10.70.0",
|
|
125
|
-
"nuxt": ">=4.5.0 <
|
|
125
|
+
"nuxt": ">=4.5.0 <6.0.0",
|
|
126
126
|
"vite": "^8.0.0"
|
|
127
127
|
},
|
|
128
128
|
"peerDependenciesMeta": {
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"@nuxt/schema": "^4.5.2",
|
|
136
136
|
"citty": "^0.2.2",
|
|
137
137
|
"drizzle-orm": "1.0.0-rc.4",
|
|
138
|
-
"@harlan-zw/nuxt-cloudflare": "^0.1
|
|
138
|
+
"@harlan-zw/nuxt-cloudflare": "^0.3.1"
|
|
139
139
|
},
|
|
140
140
|
"devDependencies": {
|
|
141
141
|
"@antfu/eslint-config": "^9.3.0",
|