nuxt-cf-jobs 0.5.1 → 0.5.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-cf-jobs",
3
3
  "configKey": "cfJobs",
4
- "version": "0.5.1",
4
+ "version": "0.5.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -69,6 +69,14 @@ export interface D1DurableJobRepositoryOptions<Queue extends string = string> {
69
69
  jobsTable?: string;
70
70
  failedJobsTable?: string;
71
71
  batchesTable?: string;
72
+ /**
73
+ * Laravel's `retry_after`: when set, `claimJob` also reclaims a reservation
74
+ * older than this many seconds (a dead worker that never acked/released), in
75
+ * one atomic statement — so a redelivered message re-runs instead of bouncing
76
+ * until DLQ. MUST be longer than the slowest job, or a still-running job can be
77
+ * double-claimed. Default unset = only unreserved rows are claimable.
78
+ */
79
+ reclaimAfterSeconds?: number;
72
80
  /** Fire-and-forget hook invoked after a successful claim. Errors are swallowed. */
73
81
  onJobClaimed?: (input: {
74
82
  job: D1DurableJobRecord<Queue>;
@@ -88,16 +88,17 @@ export function createD1DurableJobRepository(db, opts = {}) {
88
88
  },
89
89
  async claimJob(id) {
90
90
  const now = currentUnixSeconds();
91
+ const reclaimBefore = typeof opts.reclaimAfterSeconds === "number" ? now - opts.reclaimAfterSeconds : -1;
91
92
  const job = await db.prepare(`
92
93
  UPDATE ${jobsTable}
93
94
  SET reserved_at = ?, attempts = attempts + 1
94
95
  WHERE id = ?
95
- AND reserved_at IS NULL
96
+ AND (reserved_at IS NULL OR reserved_at <= ?)
96
97
  AND available_at <= ?
97
98
  AND completed_at IS NULL
98
99
  AND failed_at IS NULL
99
100
  RETURNING *
100
- `).bind(now, id, now).first();
101
+ `).bind(now, id, reclaimBefore, now).first();
101
102
  if (job)
102
103
  fireHook(() => opts.onJobClaimed?.({ job }));
103
104
  return job;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-cf-jobs",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.5.2",
5
5
  "description": "Nuxt module for typed Cloudflare queue jobs.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",