queue-jobs-worker 1.0.2 → 1.0.4

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/CHANGELOG.md CHANGED
@@ -1,128 +1,160 @@
1
- # Changelog
2
-
3
- All notable changes to **queue-jobs-worker** will be documented in this file.
4
-
5
- The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
- This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ---
9
- ## [1.0.2] — 2026-09-05
10
-
11
- ### Core
12
-
13
- ### Fixed
14
-
15
- - **`Worker` — croner added as a required dependency; invalid expressions no longer fall back to a 1-minute interval** ([#5](https://github.com/rafidahmed870/queue-jobs-worker/issues/5))
16
-
17
- `enqueueCronNext()` previously attempted a dynamic `import("croner")` inside
18
- a try/catch. If the import failed — or if the resolved `Cron` class was not a
19
- function — the code silently fell back to `Date.now() + 60_000`, scheduling
20
- the next run 60 seconds later regardless of the configured cron expression.
21
- The same silent fallback was also triggered for invalid cron expressions that
22
- caused the `Cron` constructor to throw.
23
-
24
- After the fix:
25
-
26
- - `croner` is now declared as a proper `dependency` in `package.json`
27
- (`^10.0.1`) and imported statically, so it is always available without any
28
- dynamic-import dance.
29
- - If the `Cron` constructor throws (invalid expression), a descriptive
30
- `worker:error` event is emitted and re-enqueue is skipped. The worker
31
- remains running.
32
- - If `cronInstance.nextRun()` returns `null` (the schedule has no future
33
- occurrences), a `worker:error` is emitted and re-enqueue is skipped. Again,
34
- the worker keeps running.
35
- - The 1-minute fallback path has been removed entirely — there is no silent
36
- fallback under any failure condition.
37
-
38
- - **`Worker` — rate-limit quota no longer consumed on empty-queue polls** ([#4](https://github.com/rafidahmed870/queue-jobs-worker/issues/4))
39
-
40
- `claimNext()` previously called `checkAndIncrementRateLimit()` before
41
- attempting to claim a job. This meant every poll cycle against an empty queue
42
- burned a quota slot, potentially exhausting the configured window budget
43
- before any real work was done. After the fix, the storage `claim()` call
44
- happens first; the rate-limit counter is only incremented when a job is
45
- actually claimed for processing. If the rate limit is reached at that point
46
- the lock is immediately released via `releaseLock()` so the job remains
47
- reclaimable on the next window.
48
-
49
- ---
50
-
51
- ### Events
52
-
53
- ### Added
54
-
55
- - `QueueEventEmitter` — strongly-typed lifecycle event bus shared across all components.
56
- - Emits events for the full job lifecycle: enqueued, started, completed, failed, retrying, dead, stalled.
57
- - All event payloads fully typed via `events.types.ts`.
58
-
59
- ---
60
-
61
- <!-- Links -->
62
- [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
63
-
64
- ### Storage
65
-
66
- ### Fixed
67
-
68
- - **`recoverStalledJobs()` race condition — stale recovery overwrites a live job** ([#6](https://github.com/rafidahmed870/queue-jobs-worker/issues/6))
69
-
70
- The previous implementation used a two-phase read-then-write pattern:
71
-
72
- 1. A fetch pipeline read `lockExpiresAt` and `priority` for all active jobs.
73
- 2. A separate write pipeline recovered every job whose lock appeared expired.
74
-
75
- Between those two phases a worker could complete the job, fail it, or renew
76
- its lock. The write pipeline had no knowledge of that change and would
77
- unconditionally overwrite the job back to `"waiting"`, causing duplicate
78
- processing or data loss.
79
-
80
- **`RedisStorageAdapter`** — the write pipeline has been replaced with a
81
- per-job Lua script (`RECOVER_STALLED_LUA`) that implements a
82
- **compare-and-swap (CAS)** guard. The script atomically re-reads
83
- `lockExpiresAt`, `lockId`, and `status` from the hash and aborts if any of
84
- the three values differ from what the caller observed in the read phase.
85
- Because Redis executes Lua scripts as a single indivisible command, no
86
- concurrent write can slip between the re-read and the state update. The
87
- pre-filter (skip jobs whose lock has not yet expired) is preserved as an
88
- optimisation to avoid unnecessary Lua round-trips.
89
-
90
- **`InMemoryStorageAdapter`** — all operations run within a single event-loop
91
- tick so the race is theoretical, but an equivalent CAS guard has been added
92
- for consistency: `lockId` and `lockExpiresAt` are snapshotted at decision
93
- time and re-validated immediately before the write. Any interleaving that
94
- mutated those fields will cause the recovery to be skipped.
95
-
96
- ---
97
-
98
- ## [1.0.1] — 2026-08-31
99
-
100
- ### Core
101
-
102
- ### Fixed
103
-
104
- - **`Worker.stop()` — clarified `releaseLock()` behavior in shutdown comment** ([#1](https://github.com/rafidahmed870/queue-jobs-worker/issues/1))
105
-
106
- The inline comment in `worker.ts` now correctly explains that `releaseLock()`
107
- sets `lockExpiresAt` to an already-expired timestamp (not null/empty), so
108
- `recoverStalledJobs()` on any worker will immediately reclaim the job on the
109
- next stall-check cycle.
110
-
111
- ---
112
-
113
- ### Events
114
-
115
- ### Added
116
-
117
- - `QueueEventEmitter` — strongly-typed lifecycle event bus shared across all components.
118
- - Emits events for the full job lifecycle: enqueued, started, completed, failed, retrying, dead, stalled.
119
- - All event payloads fully typed via `events.types.ts`.
120
-
121
- ---
122
-
123
- <!-- Links -->
124
-
125
- [1.0.2]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.2
126
- [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
127
- [1.0.1]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.1
128
- [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
1
+ # Changelog
2
+
3
+ All notable changes to **queue-jobs-worker** will be documented in this file.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+ ## [1.0.4] — 2026-09-13
8
+
9
+ ### Core
10
+
11
+ ### Fixed
12
+
13
+ - **`Worker` — Job timeout cooperative cancellation via `AbortSignal`** ([#12](https://github.com/rafidahmed870/queue-jobs-worker/issues/12))
14
+
15
+ Previously, when a job attempt reached its configured `timeout`, the worker rejected the internal execution promise and marked the attempt as failed (or scheduled a retry), but the underlying processor `Promise` continued running in the background. This could lead to duplicate side effects when retries overlapped with timed-out attempts.
16
+
17
+ After the fix:
18
+
19
+ - `Processor` type signature is updated: `type Processor<TPayload = unknown> = (job: Job<TPayload>, signal: AbortSignal) => Promise<void>`.
20
+ - An `AbortController` is created for each job attempt.
21
+ - When job execution times out, the worker aborts the `AbortSignal` with a timeout error before rejecting the wrapper promise.
22
+ - User processors can monitor `signal.aborted` or pass `signal` to async operations (e.g. `fetch`, database queries, timers) for cooperative cancellation.
23
+
24
+ ---
25
+
26
+ ### Events
27
+
28
+ ### Added
29
+
30
+ - `QueueEventEmitter` — strongly-typed lifecycle event bus shared across all components.
31
+ - Emits events for the full job lifecycle: enqueued, started, completed, failed, retrying, dead, stalled.
32
+ - All event payloads fully typed via `events.types.ts`.
33
+
34
+ ---
35
+
36
+ <!-- Links -->
37
+ [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
38
+
39
+ ### Storage
40
+
41
+ ### Fixed
42
+
43
+ - **`recoverStalledJobs()` race condition — stale recovery overwrites a live job** ([#6](https://github.com/rafidahmed870/queue-jobs-worker/issues/6))
44
+
45
+ The previous implementation used a two-phase read-then-write pattern:
46
+
47
+ 1. A fetch pipeline read `lockExpiresAt` and `priority` for all active jobs.
48
+ 2. A separate write pipeline recovered every job whose lock appeared expired.
49
+
50
+ Between those two phases a worker could complete the job, fail it, or renew
51
+ its lock. The write pipeline had no knowledge of that change and would
52
+ unconditionally overwrite the job back to `"waiting"`, causing duplicate
53
+ processing or data loss.
54
+
55
+ **`RedisStorageAdapter`** — the write pipeline has been replaced with a
56
+ per-job Lua script (`RECOVER_STALLED_LUA`) that implements a
57
+ **compare-and-swap (CAS)** guard. The script atomically re-reads
58
+ `lockExpiresAt`, `lockId`, and `status` from the hash and aborts if any of
59
+ the three values differ from what the caller observed in the read phase.
60
+ Because Redis executes Lua scripts as a single indivisible command, no
61
+ concurrent write can slip between the re-read and the state update. The
62
+ pre-filter (skip jobs whose lock has not yet expired) is preserved as an
63
+ optimisation to avoid unnecessary Lua round-trips.
64
+
65
+ **`InMemoryStorageAdapter`** — all operations run within a single event-loop
66
+ tick so the race is theoretical, but an equivalent CAS guard has been added
67
+ for consistency: `lockId` and `lockExpiresAt` are snapshotted at decision
68
+ time and re-validated immediately before the write. Any interleaving that
69
+ mutated those fields will cause the recovery to be skipped.
70
+
71
+ ---
72
+
73
+ ## [1.0.3] — 2026-09-09
74
+
75
+ ### Core
76
+
77
+ ### Fixed
78
+
79
+ - **`Worker` — Job timeout cooperative cancellation via `AbortSignal`** ([#12](https://github.com/rafidahmed870/queue-jobs-worker/issues/12))
80
+
81
+ Previously, when a job attempt reached its configured `timeout`, the worker rejected the internal execution promise and marked the attempt as failed (or scheduled a retry), but the underlying processor `Promise` continued running in the background. This could lead to duplicate side effects when retries overlapped with timed-out attempts.
82
+
83
+ After the fix:
84
+
85
+ - `Processor` type signature is updated: `type Processor<TPayload = unknown> = (job: Job<TPayload>, signal: AbortSignal) => Promise<void>`.
86
+ - An `AbortController` is created for each job attempt.
87
+ - When job execution times out, the worker aborts the `AbortSignal` with a timeout error before rejecting the wrapper promise.
88
+ - User processors can monitor `signal.aborted` or pass `signal` to async operations (e.g. `fetch`, database queries, timers) for cooperative cancellation.
89
+
90
+ ### Package
91
+
92
+ ### Fixed
93
+
94
+ - **`package.json` — Added `assets` to npm package `files` distribution**
95
+
96
+ Added `"assets"` to the `"files"` list in `package.json` so header banner graphics in `README.md` display properly on npmjs.com.
97
+
98
+ ---
99
+
100
+ ## [1.0.2] — 2026-09-05
101
+
102
+ ### Core
103
+
104
+ ### Fixed
105
+
106
+ - **`Worker` — croner added as a required dependency; invalid expressions no longer fall back to a 1-minute interval** ([#5](https://github.com/rafidahmed870/queue-jobs-worker/issues/5))
107
+
108
+ `enqueueCronNext()` previously attempted a dynamic `import("croner")` inside
109
+ a try/catch. If the import failed — or if the resolved `Cron` class was not a
110
+ function — the code silently fell back to `Date.now() + 60_000`, scheduling
111
+ the next run 60 seconds later regardless of the configured cron expression.
112
+ The same silent fallback was also triggered for invalid cron expressions that
113
+ caused the `Cron` constructor to throw.
114
+
115
+ After the fix:
116
+
117
+ - `croner` is now declared as a proper `dependency` in `package.json`
118
+ (`^10.0.1`) and imported statically, so it is always available without any
119
+ dynamic-import dance.
120
+ - If the `Cron` constructor throws (invalid expression), a descriptive
121
+ `worker:error` event is emitted and re-enqueue is skipped. The worker
122
+ remains running.
123
+ - If `cronInstance.nextRun()` returns `null` (the schedule has no future
124
+ occurrences), a `worker:error` is emitted and re-enqueue is skipped. Again,
125
+ the worker keeps running.
126
+ - The 1-minute fallback path has been removed entirely — there is no silent
127
+ fallback under any failure condition.
128
+
129
+ - **`Worker` — rate-limit quota no longer consumed on empty-queue polls** ([#4](https://github.com/rafidahmed870/queue-jobs-worker/issues/4))
130
+
131
+ `claimNext()` previously called `checkAndIncrementRateLimit()` before
132
+ attempting to claim a job. This meant every poll cycle against an empty queue
133
+ burned a quota slot, potentially exhausting the configured window budget
134
+ before any real work was done. After the fix, the storage `claim()` call
135
+ happens first; the rate-limit counter is only incremented when a job is
136
+ actually claimed for processing. If the rate limit is reached at that point
137
+ the lock is immediately released via `releaseLock()` so the job remains
138
+ reclaimable on the next window.
139
+
140
+ ---
141
+
142
+ ### Events
143
+
144
+ ### Added
145
+
146
+ - `QueueEventEmitter` — strongly-typed lifecycle event bus shared across all components.
147
+ - Emits events for the full job lifecycle: enqueued, started, completed, failed, retrying, dead, stalled.
148
+ - All event payloads fully typed via `events.types.ts`.
149
+
150
+ ---
151
+
152
+ <!-- Links -->
153
+
154
+ [1.0.4]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.4
155
+ [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
156
+ [1.0.3]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.2...v1.0.3
157
+ [1.0.2]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.1...v1.0.2
158
+ [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
159
+ [1.0.1]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.1
160
+ [1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0