queue-jobs-worker 1.0.5 → 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.
- package/README.md +754 -572
- package/dist/index.d.ts +546 -29
- package/dist/index.js +1268 -2448
- package/dist/scripts/claim-job.lua +117 -0
- package/dist/scripts/clear-queue.lua +42 -0
- package/dist/scripts/list-jobs.lua +50 -0
- package/dist/scripts/remove-job.lua +41 -0
- package/dist/scripts/save-job.lua +52 -0
- package/dist/scripts/update-job.lua +183 -0
- package/package.json +91 -110
- package/CHANGELOG.md +0 -133
- package/LICENSE +0 -21
- package/assets/queue-jobs-worker-demo.gif +0 -0
- package/assets/queue-jobs-worker-github.png +0 -0
- package/dist/core/backoff.d.ts +0 -24
- package/dist/core/backoff.d.ts.map +0 -1
- package/dist/core/client.d.ts +0 -95
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/id.d.ts +0 -9
- package/dist/core/id.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/job.d.ts +0 -75
- package/dist/core/job.d.ts.map +0 -1
- package/dist/core/queue.d.ts +0 -72
- package/dist/core/queue.d.ts.map +0 -1
- package/dist/core/worker.d.ts +0 -65
- package/dist/core/worker.d.ts.map +0 -1
- package/dist/events/emitter.d.ts +0 -24
- package/dist/events/emitter.d.ts.map +0 -1
- package/dist/index.cjs +0 -2578
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/scripts/claim.lua +0 -27
- package/dist/lib/scripts/index.d.ts +0 -5
- package/dist/lib/scripts/index.d.ts.map +0 -1
- package/dist/lib/scripts/rate-limit.lua +0 -36
- package/dist/lib/scripts/recover-stalled.lua +0 -40
- package/dist/lib/scripts/renew-lock.lua +0 -16
- package/dist/storage/in-memory.adapter.d.ts +0 -33
- package/dist/storage/in-memory.adapter.d.ts.map +0 -1
- package/dist/storage/index.d.ts +0 -5
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/mysql.adapter.d.ts +0 -38
- package/dist/storage/mysql.adapter.d.ts.map +0 -1
- package/dist/storage/postgres.adapter.d.ts +0 -38
- package/dist/storage/postgres.adapter.d.ts.map +0 -1
- package/dist/storage/redis.adapter.d.ts +0 -45
- package/dist/storage/redis.adapter.d.ts.map +0 -1
- package/dist/types/client.types.d.ts +0 -41
- package/dist/types/client.types.d.ts.map +0 -1
- package/dist/types/events.types.d.ts +0 -22
- package/dist/types/events.types.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/job.types.d.ts +0 -97
- package/dist/types/job.types.d.ts.map +0 -1
- package/dist/types/queue.types.d.ts +0 -43
- package/dist/types/queue.types.d.ts.map +0 -1
- package/dist/types/storage.types.d.ts +0 -138
- package/dist/types/storage.types.d.ts.map +0 -1
- package/dist/types/worker.types.d.ts +0 -25
- 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": "
|
|
4
|
-
"description": "Reliable job queue and
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"queue"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"worker"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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,133 +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
|
-
|
|
8
|
-
## [1.0.5] — 2026-09-15
|
|
9
|
-
|
|
10
|
-
### Core
|
|
11
|
-
|
|
12
|
-
### Fixed
|
|
13
|
-
|
|
14
|
-
- **Storage Initialization Enforcement prior to Queue Creation & Execution** ([#14](https://github.com/rafidahmed870/queue-jobs-worker/issues/14))
|
|
15
|
-
|
|
16
|
-
Previously, `QueueClient.createQueue()` allowed queues to be created before `await client.init()` was called when using external storage dialects (e.g. Redis, PostgreSQL, MySQL). This caused the created queue to bind to the temporary `InMemoryStorageAdapter` instance. When `client.init()` was subsequently called, the real external storage adapter replaced the internal storage field on `QueueClient`, rendering previously enqueued jobs lost or inaccessible.
|
|
17
|
-
|
|
18
|
-
After the fix:
|
|
19
|
-
|
|
20
|
-
- `QueueClient.createQueue()` checks `isInitialised` before creating a queue. For external dialects and custom adapters, attempting to create a queue before `await client.init()` throws an explicit error.
|
|
21
|
-
- Queue operations (`enqueue`, `getJob`, `getJobs`, `getJobCounts`, and `createWorker`) enforce initialization status checks before executing, preventing operations on uninitialized storage.
|
|
22
|
-
- In-memory dialect continues to auto-initialize synchronously, preserving convenient single-line setup for tests and local development.
|
|
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
|
-
### Lib
|
|
40
|
-
|
|
41
|
-
### Added
|
|
42
|
-
|
|
43
|
-
- **`lib/scripts/` — Redis Lua scripts extracted to standalone `.lua` files**
|
|
44
|
-
- `claim.lua` — atomic job claim with delayed-job promotion.
|
|
45
|
-
- `recover-stalled.lua` — compare-and-swap stalled job recovery.
|
|
46
|
-
- `renew-lock.lua` — atomic lock renewal with ownership guard.
|
|
47
|
-
- `rate-limit.lua` — atomic rate limit decision, reset, and counter increment.
|
|
48
|
-
- `lib/scripts/index.ts` re-exports scripts as named string constants (`CLAIM_LUA`, `RECOVER_STALLED_LUA`, `RENEW_LOCK_LUA`, `RATE_LIMIT_LUA`).
|
|
49
|
-
- Scripts are embedded into the CJS/ESM distribution bundles at build time via `tsup`'s `loader: { ".lua": "text" }`.
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
### Storage
|
|
54
|
-
|
|
55
|
-
### Added
|
|
56
|
-
|
|
57
|
-
- **Consistent timestamps across Lua scripts**
|
|
58
|
-
- Changed `RedisStorageAdapter` to use `now_iso` from `ARGV[3]` for `updatedAt` in `CLAIM_LUA` and `RECOVER_STALLED_LUA`.
|
|
59
|
-
- Previously, `updatedAt` was sometimes derived from `lockExpiresAt`, which could differ from the actual time of the operation.
|
|
60
|
-
|
|
61
|
-
### Fixed
|
|
62
|
-
|
|
63
|
-
- **Atomic rate limiting across Redis, PostgreSQL, and MySQL adapters**
|
|
64
|
-
- `RedisStorageAdapter`: Implemented `rate-limit.lua` (`RATE_LIMIT_LUA`) script to perform window check, expiry reset, counter evaluation, increment, and TTL renewal atomically inside Redis.
|
|
65
|
-
- `PostgreSQLStorageAdapter`: Wrapped `checkAndIncrementRateLimit` in a pool client transaction (`BEGIN ... COMMIT`) utilizing `INSERT ... ON CONFLICT DO NOTHING` and `SELECT ... FOR UPDATE` row locking.
|
|
66
|
-
- `MySQLStorageAdapter`: Wrapped `checkAndIncrementRateLimit` in a connection transaction (`beginTransaction ... commit`) utilizing `INSERT ... ON DUPLICATE KEY UPDATE` and `SELECT ... FOR UPDATE` row locking.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
### Types
|
|
72
|
-
|
|
73
|
-
### Added
|
|
74
|
-
|
|
75
|
-
- **`lua.d.ts` — ambient module declaration for `.lua` imports**
|
|
76
|
-
- Declares `declare module "*.lua"` so TypeScript recognises `.lua` files as `string`-exporting modules.
|
|
77
|
-
- Required by `src/lib/scripts/index.ts` to import Lua scripts directly without type errors.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
### Tests
|
|
82
|
-
|
|
83
|
-
### Added
|
|
84
|
-
|
|
85
|
-
- **`lua-scripts.test.ts` — unit tests for Redis Lua scripts**
|
|
86
|
-
- 22 tests covering all four Lua scripts (`CLAIM_LUA`, `RECOVER_STALLED_LUA`, `RENEW_LOCK_LUA`, `RATE_LIMIT_LUA`).
|
|
87
|
-
- Verifies each script loads as a non-empty string from `src/lib/scripts/index.ts`.
|
|
88
|
-
- Asserts presence of critical Redis commands (`ZPOPMIN`, `ZRANGEBYSCORE`, `SADD`, `HSET`, `SREM`, `ZADD`, `INCR`, `EXPIRE`) and CAS/RateLimit guard conditions.
|
|
89
|
-
- **`vitest.config.ts` — `rawLuaPlugin` added**
|
|
90
|
-
- Custom Vite transform plugin that loads `.lua` files as raw text strings during tests, mirroring `tsup`'s `loader: { ".lua": "text" }` used at build time.
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## [1.0.4] — 2026-09-13
|
|
95
|
-
|
|
96
|
-
### Core
|
|
97
|
-
|
|
98
|
-
### Fixed
|
|
99
|
-
|
|
100
|
-
- **`Worker` — Job timeout cooperative cancellation via `AbortSignal`** ([#12](https://github.com/rafidahmed870/queue-jobs-worker/issues/12))
|
|
101
|
-
|
|
102
|
-
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.
|
|
103
|
-
|
|
104
|
-
After the fix:
|
|
105
|
-
|
|
106
|
-
- `Processor` type signature is updated: `type Processor<TPayload = unknown> = (job: Job<TPayload>, signal: AbortSignal) => Promise<void>`.
|
|
107
|
-
- An `AbortController` is created for each job attempt.
|
|
108
|
-
- When job execution times out, the worker aborts the `AbortSignal` with a timeout error before rejecting the wrapper promise.
|
|
109
|
-
- User processors can monitor `signal.aborted` or pass `signal` to async operations (e.g. `fetch`, database queries, timers) for cooperative cancellation.
|
|
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.5]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.5
|
|
126
|
-
[1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
|
|
127
|
-
[1.0.4]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.4
|
|
128
|
-
[1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
|
|
129
|
-
[1.0.3]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.2...v1.0.3
|
|
130
|
-
[1.0.2]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.1...v1.0.2
|
|
131
|
-
[1.0.0]: https://github.com/rafidahmed870/queue-jobs-worker/releases/tag/v1.0.0
|
|
132
|
-
[1.0.1]: https://github.com/rafidahmed870/queue-jobs-worker/compare/v1.0.0...v1.0.1
|
|
133
|
-
[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
|
package/dist/core/backoff.d.ts
DELETED
|
@@ -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"}
|
package/dist/core/client.d.ts
DELETED
|
@@ -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
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E,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,SAAS;IAIvE,wDAAwD;IACxD,YAAY,CAAC,QAAQ,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC;IAQ/D,qDAAqD;IACrD,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IAED,wDAAwD;IACxD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAMD,EAAE,CAAC,CAAC,SAAS,MAAM,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,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;CAOf"}
|
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
|
package/dist/core/id.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/core/index.d.ts
DELETED
|
@@ -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
|
package/dist/core/index.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/core/job.d.ts
DELETED
|
@@ -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
|
package/dist/core/job.d.ts.map
DELETED
|
@@ -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,6C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