queue-jobs-worker 1.0.4 → 2.0.0

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.
Files changed (58) hide show
  1. package/README.md +754 -538
  2. package/dist/index.d.ts +546 -29
  3. package/dist/index.js +1279 -2410
  4. package/dist/scripts/claim-job.lua +117 -0
  5. package/dist/scripts/clear-queue.lua +42 -0
  6. package/dist/scripts/list-jobs.lua +50 -0
  7. package/dist/scripts/remove-job.lua +41 -0
  8. package/dist/scripts/save-job.lua +52 -0
  9. package/dist/scripts/update-job.lua +183 -0
  10. package/package.json +91 -110
  11. package/CHANGELOG.md +0 -160
  12. package/LICENSE +0 -21
  13. package/assets/queue-jobs-worker-demo.mp4 +0 -0
  14. package/assets/queue-jobs-worker-github.png +0 -0
  15. package/dist/core/backoff.d.ts +0 -24
  16. package/dist/core/backoff.d.ts.map +0 -1
  17. package/dist/core/client.d.ts +0 -95
  18. package/dist/core/client.d.ts.map +0 -1
  19. package/dist/core/id.d.ts +0 -9
  20. package/dist/core/id.d.ts.map +0 -1
  21. package/dist/core/index.d.ts +0 -7
  22. package/dist/core/index.d.ts.map +0 -1
  23. package/dist/core/job.d.ts +0 -75
  24. package/dist/core/job.d.ts.map +0 -1
  25. package/dist/core/queue.d.ts +0 -70
  26. package/dist/core/queue.d.ts.map +0 -1
  27. package/dist/core/worker.d.ts +0 -65
  28. package/dist/core/worker.d.ts.map +0 -1
  29. package/dist/events/emitter.d.ts +0 -24
  30. package/dist/events/emitter.d.ts.map +0 -1
  31. package/dist/index.cjs +0 -2529
  32. package/dist/index.cjs.map +0 -1
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/index.js.map +0 -1
  35. package/dist/storage/in-memory.adapter.d.ts +0 -33
  36. package/dist/storage/in-memory.adapter.d.ts.map +0 -1
  37. package/dist/storage/index.d.ts +0 -5
  38. package/dist/storage/index.d.ts.map +0 -1
  39. package/dist/storage/mysql.adapter.d.ts +0 -38
  40. package/dist/storage/mysql.adapter.d.ts.map +0 -1
  41. package/dist/storage/postgres.adapter.d.ts +0 -38
  42. package/dist/storage/postgres.adapter.d.ts.map +0 -1
  43. package/dist/storage/redis.adapter.d.ts +0 -45
  44. package/dist/storage/redis.adapter.d.ts.map +0 -1
  45. package/dist/types/client.types.d.ts +0 -41
  46. package/dist/types/client.types.d.ts.map +0 -1
  47. package/dist/types/events.types.d.ts +0 -22
  48. package/dist/types/events.types.d.ts.map +0 -1
  49. package/dist/types/index.d.ts +0 -10
  50. package/dist/types/index.d.ts.map +0 -1
  51. package/dist/types/job.types.d.ts +0 -97
  52. package/dist/types/job.types.d.ts.map +0 -1
  53. package/dist/types/queue.types.d.ts +0 -43
  54. package/dist/types/queue.types.d.ts.map +0 -1
  55. package/dist/types/storage.types.d.ts +0 -138
  56. package/dist/types/storage.types.d.ts.map +0 -1
  57. package/dist/types/worker.types.d.ts +0 -25
  58. package/dist/types/worker.types.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,110 +1,91 @@
1
- {
2
- "name": "queue-jobs-worker",
3
- "version": "1.0.4",
4
- "description": "Reliable job queue and background worker system for Node.js with retries, concurrency, scheduling, and failure recovery.",
5
- "keywords": [
6
- "queue-jobs-worker",
7
- "queue",
8
- "job-queue",
9
- "background-jobs",
10
- "background-processing",
11
- "worker",
12
- "nodejs",
13
- "retry-jobs",
14
- "concurrency",
15
- "scheduling",
16
- "dlq",
17
- "dead-letter-queue",
18
- "redis",
19
- "postgres",
20
- "mysql",
21
- "typescript"
22
- ],
23
- "homepage": "https://github.com/rafidahmed870/queue-jobs-worker#readme",
24
- "bugs": {
25
- "url": "https://github.com/rafidahmed870/queue-jobs-worker/issues"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/rafidahmed870/queue-jobs-worker.git"
30
- },
31
- "license": "MIT",
32
- "author": "Rafid Ahmed",
33
- "type": "module",
34
- "main": "./dist/index.cjs",
35
- "module": "./dist/index.js",
36
- "types": "./dist/index.d.ts",
37
- "exports": {
38
- ".": {
39
- "import": {
40
- "types": "./dist/index.d.ts",
41
- "default": "./dist/index.js"
42
- },
43
- "require": {
44
- "types": "./dist/index.d.ts",
45
- "default": "./dist/index.cjs"
46
- }
47
- }
48
- },
49
- "sideEffects": false,
50
- "files": [
51
- "dist",
52
- "assets",
53
- "README.md",
54
- "CHANGELOG.md",
55
- "LICENSE"
56
- ],
57
- "scripts": {
58
- "build": "tsup && tsc -p tsconfig.dts.json",
59
- "dev": "tsup --watch",
60
- "typecheck": "tsc --noEmit",
61
- "lint": "eslint .",
62
- "lint:fix": "eslint . --fix",
63
- "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
64
- "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
65
- "test": "vitest run",
66
- "test:watch": "vitest",
67
- "test:coverage": "vitest run --coverage",
68
- "prepublishOnly": "npm run typecheck && npm run build",
69
- "prepare": "husky"
70
- },
71
- "engines": {
72
- "node": ">=18.0.0"
73
- },
74
- "dependencies": {
75
- "croner": "^10.0.1"
76
- },
77
- "peerDependencies": {
78
- "mysql2": ">=3.0.0",
79
- "pg": ">=8.0.0",
80
- "redis": ">=4.0.0"
81
- },
82
- "peerDependenciesMeta": {
83
- "redis": {
84
- "optional": true
85
- },
86
- "pg": {
87
- "optional": true
88
- },
89
- "mysql2": {
90
- "optional": true
91
- }
92
- },
93
- "devDependencies": {
94
- "@types/node": "*",
95
- "@types/pg": "^8.23.1",
96
- "@typescript-eslint/eslint-plugin": "*",
97
- "@typescript-eslint/parser": "*",
98
- "eslint": "*",
99
- "eslint-config-prettier": "*",
100
- "eslint-plugin-prettier": "*",
101
- "husky": "^9.1.7",
102
- "mysql2": "^3.24.2",
103
- "pg": "^8.23.0",
104
- "prettier": "*",
105
- "redis": "^6.2.1",
106
- "tsup": "*",
107
- "typescript": "*",
108
- "vitest": "*"
109
- }
110
- }
1
+ {
2
+ "name": "queue-jobs-worker",
3
+ "version": "2.0.0",
4
+ "description": "Reliable background job queue and worker system for Node.js — supports in-memory, Redis, PostgreSQL, and MySQL with retries, concurrency, scheduling, and failure recovery.",
5
+ "homepage": "https://github.com/rafidahmed870/queue-jobs-worker#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/rafidahmed870/queue-jobs-worker/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/rafidahmed870/queue-jobs-worker.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Rafid Ahmed",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "registry": "https://registry.npmjs.org/"
30
+ },
31
+ "packageManager": "pnpm@11.22.0",
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "build:tsc": "tsc",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest",
37
+ "format": "prettier --write .",
38
+ "prepare": "husky",
39
+ "prepublishOnly": "pnpm build"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "keywords": [
45
+ "queue",
46
+ "worker",
47
+ "job",
48
+ "background",
49
+ "task",
50
+ "scheduler",
51
+ "cron",
52
+ "redis",
53
+ "postgres",
54
+ "mysql",
55
+ "retry",
56
+ "concurrency"
57
+ ],
58
+ "devDependencies": {
59
+ "@types/node": "^26.6.1",
60
+ "@types/pg": "^8.23.1",
61
+ "@typescript-eslint/eslint-plugin": "^8.70.0",
62
+ "@typescript-eslint/parser": "^8.70.0",
63
+ "eslint": "^10.10.0",
64
+ "eslint-config-prettier": "^10.1.8",
65
+ "eslint-plugin-prettier": "^5.5.6",
66
+ "husky": "^9.1.7",
67
+ "prettier": "^3.9.8",
68
+ "tsup": "^8.5.1",
69
+ "typescript": "^5.8.3",
70
+ "vitest": "^5.0.1"
71
+ },
72
+ "dependencies": {
73
+ "croner": "^10.0.1"
74
+ },
75
+ "peerDependencies": {
76
+ "mysql2": ">=3.0.0",
77
+ "pg": ">=8.0.0",
78
+ "redis": ">=4.0.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "redis": {
82
+ "optional": true
83
+ },
84
+ "pg": {
85
+ "optional": true
86
+ },
87
+ "mysql2": {
88
+ "optional": true
89
+ }
90
+ }
91
+ }
package/CHANGELOG.md DELETED
@@ -1,160 +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
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Rafid Ahmed
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
Binary file
Binary file
@@ -1,24 +0,0 @@
1
- /**
2
- * Backoff strategies
3
- *
4
- * Calculates the delay (in ms) before a failed job is re-queued.
5
- *
6
- * - fixed — always uses `baseDelay`
7
- * - linear — baseDelay × attemptNumber
8
- * - exponential — baseDelay × 2^(attemptNumber - 1), capped at MAX_DELAY
9
- */
10
- import type { BackoffStrategy } from "../types/job.types.js";
11
- /**
12
- * Returns the retry delay in milliseconds for the given attempt.
13
- *
14
- * @param strategy - Backoff strategy name.
15
- * @param baseDelay - Base delay in ms (from job / queue / client config).
16
- * @param attemptNumber - The 1-based attempt number that just failed.
17
- */
18
- export declare function calculateBackoff(strategy: BackoffStrategy, baseDelay: number, attemptNumber: number): number;
19
- /**
20
- * Returns the ISO timestamp at which a job should next become eligible,
21
- * given the current time and the calculated delay.
22
- */
23
- export declare function nextRunAt(delayMs: number, fromDate?: Date): string;
24
- //# sourceMappingURL=backoff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/core/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,MAAM,CAuBR;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,IAAiB,GAAG,MAAM,CAE9E"}
@@ -1,95 +0,0 @@
1
- /**
2
- * QueueClient
3
- *
4
- * Primary entry point for the queue-jobs-worker package.
5
- *
6
- * Usage:
7
- *
8
- * // In-memory (dev / tests)
9
- * const client = new QueueClient();
10
- * // init() is optional for "memory" but always safe to call
11
- *
12
- * // Redis
13
- * const client = new QueueClient({ dialect: "redis", connectionString: "redis://localhost:6379" });
14
- * await client.init(); // connects, pings Redis
15
- *
16
- * // PostgreSQL
17
- * const client = new QueueClient({ dialect: "postgres", connectionString: "postgresql://..." });
18
- * await client.init(); // connects, auto-creates qjw_ tables if missing
19
- *
20
- * // MySQL
21
- * const client = new QueueClient({ dialect: "mysql", connectionString: "mysql://..." });
22
- * await client.init(); // connects, auto-creates qjw_ tables if missing
23
- */
24
- import type { QueueClientOptions } from "../types/client.types.js";
25
- import type { QueueOptions } from "../types/queue.types.js";
26
- import type { StorageAdapter } from "../types/storage.types.js";
27
- import type { QueueEvents } from "../types/events.types.js";
28
- import { Queue } from "./queue.js";
29
- export declare class QueueClient {
30
- /** @internal — mutable so withAdapter() can replace it */
31
- _storage: StorageAdapter;
32
- private readonly emitter;
33
- private readonly defaults;
34
- private readonly dialect;
35
- private readonly connectionString;
36
- private readonly queues;
37
- private initialised;
38
- private closed;
39
- /** True when the adapter was supplied via {@link withAdapter}; init() skips resolveAdapter() in that case. */
40
- private _customAdapter;
41
- constructor(options?: QueueClientOptions);
42
- private buildMemoryOrEagerAdapter;
43
- /**
44
- * Initialise the client and storage adapter.
45
- *
46
- * **Must be called** before creating queues when using Redis, PostgreSQL,
47
- * or MySQL.
48
- *
49
- * What each adapter does:
50
- * - **memory** — no-op (always safe to call)
51
- * - **redis** — connects, sends PING, verifies PONG
52
- * - **postgres** — connects, runs `SELECT 1`, auto-creates `qjw_` tables
53
- * - **mysql** — connects, runs `SELECT 1`, auto-creates `qjw_` tables
54
- *
55
- * Idempotent — safe to call multiple times.
56
- */
57
- init(): Promise<void>;
58
- /** @deprecated Use `init()`. */
59
- initialize(): Promise<void>;
60
- private resolveAdapter;
61
- /**
62
- * Create a named queue with optional per-queue configuration.
63
- *
64
- * For external dialects (redis/postgres/mysql), call `await client.init()`
65
- * first.
66
- */
67
- createQueue<TPayload = unknown>(name: string, options?: QueueOptions): Queue<TPayload>;
68
- /** Returns the queue with the given name, or `undefined`. */
69
- getQueue<TPayload = unknown>(name: string): Queue<TPayload> | undefined;
70
- /** Returns the queue with the given name, or throws. */
71
- requireQueue<TPayload = unknown>(name: string): Queue<TPayload>;
72
- /** Names of all queues registered on this client. */
73
- get queueNames(): string[];
74
- /** `true` after `init()` has completed successfully. */
75
- get isInitialised(): boolean;
76
- on<K extends keyof QueueEvents>(event: K, listener: (...args: QueueEvents[K]) => void): this;
77
- once<K extends keyof QueueEvents>(event: K, listener: (...args: QueueEvents[K]) => void): this;
78
- off<K extends keyof QueueEvents>(event: K, listener: (...args: QueueEvents[K]) => void): this;
79
- /**
80
- * Stop all workers, close all queues, and release the storage connection.
81
- * Safe to call multiple times.
82
- */
83
- close(): Promise<void>;
84
- /**
85
- * Create a QueueClient with a fully custom StorageAdapter.
86
- *
87
- * `init()` will call `adapter.initialize()`.
88
- *
89
- * @example
90
- * const client = QueueClient.withAdapter(myAdapter);
91
- * await client.init();
92
- */
93
- static withAdapter(adapter: StorageAdapter, options?: Omit<QueueClientOptions, "dialect" | "connectionString">): QueueClient;
94
- }
95
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,0BAA0B,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,KAA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AAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAK5F,IAAI,CAAC,CAAC,SAAS,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAK9F,GAAG,CAAC,CAAC,SAAS,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI;IAS7F;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAChB,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,kBAAkB,CAAM,GACrE,WAAW;CAMf"}
package/dist/core/id.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * Job ID generation
3
- *
4
- * Uses the built-in `crypto.randomUUID()` available in Node.js >= 14.17.
5
- * No external dependency needed.
6
- */
7
- /** Generate a new unique job ID. */
8
- export declare function generateJobId(): string;
9
- //# sourceMappingURL=id.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/core/id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,oCAAoC;AACpC,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
@@ -1,7 +0,0 @@
1
- export { Job } from "./job.js";
2
- export { Queue } from "./queue.js";
3
- export { Worker } from "./worker.js";
4
- export { QueueClient } from "./client.js";
5
- export { calculateBackoff, nextRunAt } from "./backoff.js";
6
- export { generateJobId } from "./id.js";
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
@@ -1,75 +0,0 @@
1
- /**
2
- * Job
3
- *
4
- * A rich wrapper around the raw JobData record stored in the storage layer.
5
- * Exposes read-only accessors for all fields and a small set of helpers used
6
- * by Queue and Worker internals.
7
- *
8
- * The Job instance is passed directly to user-supplied Processor functions.
9
- * Users should never mutate the internal data object — all mutations happen
10
- * through the storage adapter.
11
- */
12
- import type { JobData, JobStatus, JobAttempt, BackoffStrategy } from "../types/job.types.js";
13
- export declare class Job<TPayload = unknown> {
14
- /** @internal Raw data record — treat as immutable outside storage layer. */
15
- readonly _data: JobData<TPayload>;
16
- constructor(data: JobData<TPayload>);
17
- /** Unique, stable job identifier. */
18
- get id(): string;
19
- /** Name of the queue this job belongs to. */
20
- get queue(): string;
21
- /** Application-defined job type (matches the registered processor). */
22
- get type(): string;
23
- /**
24
- * User-supplied job payload.
25
- * Never log this value — it may contain sensitive data.
26
- */
27
- get data(): TPayload;
28
- /** Current lifecycle status. */
29
- get status(): JobStatus;
30
- /** Number of attempts already executed (0 = not yet started). */
31
- get attemptsMade(): number;
32
- /** Maximum allowed attempts. */
33
- get maxAttempts(): number;
34
- /** How many attempts remain (including the current one). */
35
- get attemptsRemaining(): number;
36
- /** Ordered list of past attempt records. */
37
- get attemptHistory(): readonly JobAttempt[];
38
- /** Base delay in ms between retry attempts. */
39
- get retryDelay(): number;
40
- /** Backoff strategy applied on retry. */
41
- get backoff(): BackoffStrategy;
42
- /** Per-attempt timeout in ms. */
43
- get timeout(): number;
44
- /** Processing priority — higher numbers are processed first. */
45
- get priority(): number;
46
- /** ISO timestamp when this job is eligible to run. */
47
- get runAt(): string;
48
- /** Cron expression for recurring jobs, or undefined. */
49
- get cron(): string | undefined;
50
- /** ID of the worker currently holding the lock, or null. */
51
- get lockId(): string | null;
52
- /** ISO timestamp when the current lock expires, or null. */
53
- get lockExpiresAt(): string | null;
54
- /** ISO timestamp when the job was first enqueued. */
55
- get createdAt(): string;
56
- /** ISO timestamp of the last status change. */
57
- get updatedAt(): string;
58
- /** ISO timestamp when the job completed successfully, or null. */
59
- get completedAt(): string | null;
60
- /** ISO timestamp when the job was moved to the DLQ, or null. */
61
- get failedAt(): string | null;
62
- /** Returns true when the job has been successfully processed. */
63
- isCompleted(): boolean;
64
- /** Returns true when the job is in the Dead Letter Queue. */
65
- isDead(): boolean;
66
- /** Returns true when the job is currently being processed by a worker. */
67
- isActive(): boolean;
68
- /** Returns true when the job is waiting to be claimed. */
69
- isWaiting(): boolean;
70
- /** Returns true when the job is scheduled for a future time. */
71
- isDelayed(): boolean;
72
- toJSON(): Record<string, unknown>;
73
- toString(): string;
74
- }
75
- //# sourceMappingURL=job.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../../src/core/job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7F,qBAAa,GAAG,CAAC,QAAQ,GAAG,OAAO;IACjC,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAEtB,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC;IAQnC,qCAAqC;IACrC,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,6CAA6C;IAC7C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,uEAAuE;IACvE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAMD;;;OAGG;IACH,IAAI,IAA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