@zudojs/queue 1.4.0 → 1.4.1

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 CHANGED
@@ -57,6 +57,35 @@ console.log(await queue.getStats());
57
57
  await queue.close();
58
58
  ```
59
59
 
60
+ ## Dead-letter store
61
+
62
+ Each queue keeps the most recent 1000 dead-lettered jobs in a store of its own,
63
+ cleared by `close()`. To choose the cap, or to keep the jobs after the queue
64
+ closes, pass a store as `deadLetterStore`. No type annotation is needed, for
65
+ an untyped store or one typed for the queue's payload.
66
+
67
+ ```typescript
68
+ import {
69
+ createInMemoryDeadLetterStore,
70
+ createInMemoryQueue,
71
+ createQueueName,
72
+ } from "@zudojs/queue";
73
+
74
+ // Keep only the 50 most recent failures.
75
+ const store = createInMemoryDeadLetterStore({ maxEntries: 50 });
76
+ const broken = createInMemoryQueue(createQueueName("broken"), {
77
+ deadLetterStore: store,
78
+ });
79
+
80
+ // A store typed for the payload, so its entries read as DeadLetterJob<Email>.
81
+ const failedEmails = createInMemoryDeadLetterStore<Email>();
82
+ const emails = createInMemoryQueue<Email>(createQueueName("emails"), {
83
+ deadLetterStore: failedEmails,
84
+ });
85
+ ```
86
+
87
+ `close()` leaves a store you passed in alone; its contents are yours.
88
+
60
89
  ## Features
61
90
 
62
91
  - In-memory queue for development and testing
@@ -81,6 +81,9 @@ export class InMemoryQueue {
81
81
  this.emitter.setLogger(this.options.logger);
82
82
  }
83
83
  this.ownsDeadLetterStore = this.options.deadLetterStore === undefined;
84
+ // A caller's store is typed `DeadLetterStore<unknown>` (see
85
+ // `QueueOptions.deadLetterStore`); this queue only ever adds its own
86
+ // `TData` jobs to it, so it is read back as a store of `TData`.
84
87
  this.deadLetterStore =
85
88
  this.options.deadLetterStore ??
86
89
  createInMemoryDeadLetterStore({
@@ -63,8 +63,15 @@ export interface QueueOptions {
63
63
  * emitter, reachable as `queue.events`.
64
64
  */
65
65
  readonly eventEmitter?: QueueEventEmitter;
66
- /** Store that receives jobs which exhausted their attempts. */
67
- readonly deadLetterStore?: DeadLetterStore<never>;
66
+ /**
67
+ * Store that receives jobs which exhausted their attempts.
68
+ *
69
+ * Any store is accepted without an annotation: the untyped
70
+ * `createInMemoryDeadLetterStore()` and one typed for the queue's payload,
71
+ * `createInMemoryDeadLetterStore<TData>()`. (1.4.0 typed this
72
+ * `DeadLetterStore<never>`, which rejected both.)
73
+ */
74
+ readonly deadLetterStore?: DeadLetterStore<unknown>;
68
75
  /**
69
76
  * Whether `add()` rejects while the queue is paused.
70
77
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/queue",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Background job and asynchronous task infrastructure with in-memory and adapter-based queue implementations.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@zudojs/errors": "1.3.0",
29
29
  "@zudojs/constants": "1.1.2",
30
- "@zudojs/serialization": "1.2.0"
30
+ "@zudojs/serialization": "1.2.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "7.0.2",