@imqueue/core 3.4.1 → 3.4.3

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.
@@ -154,11 +154,15 @@ export interface IMessageQueueConnection extends IMessageQueueAuthConnection {
154
154
  */
155
155
  id?: string;
156
156
  /**
157
- * Host name or IP address of the queue host. Defaults to `localhost`.
157
+ * Host name or IP address of the queue host.
158
+ *
159
+ * @defaultValue "localhost"
158
160
  */
159
161
  host: string;
160
162
  /**
161
- * TCP port of the queue host. Defaults to `6379`.
163
+ * TCP port of the queue host.
164
+ *
165
+ * @defaultValue 6379
162
166
  */
163
167
  port: number;
164
168
  }
@@ -196,8 +200,9 @@ export interface IMessageQueueAuthConnection {
196
200
  */
197
201
  export interface IMQOptions extends Partial<IMessageQueueConnection> {
198
202
  /**
199
- * Turns on/off the watcher's periodic removal of orphaned keys. Defaults to
200
- * `false`.
203
+ * Turns on/off the watcher's periodic removal of orphaned keys.
204
+ *
205
+ * @defaultValue false
201
206
  *
202
207
  * @remarks
203
208
  * This is a destructive sweep. Only the instance holding the watcher lock
@@ -211,9 +216,11 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
211
216
  cleanup: boolean;
212
217
  /**
213
218
  * Redis glob pattern, appended to the prefix as `<prefix>:<cleanupFilter>`,
214
- * selecting which keys the cleanup sweep considers. Defaults to `'*'` —
219
+ * selecting which keys the cleanup sweep considers. The default matches
215
220
  * every key in the namespace.
216
221
  *
222
+ * @defaultValue "*"
223
+ *
217
224
  * @remarks
218
225
  * This matches Redis key names, not queue names. The same pattern is also
219
226
  * matched against connection names when deciding which keys belong to live
@@ -221,8 +228,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
221
228
  */
222
229
  cleanupFilter: string;
223
230
  /**
224
- * Queue adapter vendor name. Defaults to `'Redis'`, which is the only
225
- * supported value.
231
+ * Queue adapter vendor name, and the only supported value.
232
+ *
233
+ * @defaultValue "Redis"
226
234
  *
227
235
  * @remarks
228
236
  * Honoured only by {@link IMQ.create}, which throws a `TypeError` for any
@@ -231,7 +239,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
231
239
  */
232
240
  vendor?: string;
233
241
  /**
234
- * Global key namespace for everything this queue writes. Defaults to `'imq'`.
242
+ * Global key namespace for everything this queue writes.
243
+ *
244
+ * @defaultValue "imq"
235
245
  *
236
246
  * @remarks
237
247
  * The prefix scopes more than the queue keys: it also scopes the delayed set,
@@ -243,7 +253,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
243
253
  */
244
254
  prefix?: string;
245
255
  /**
246
- * Logger used for queue diagnostics. Defaults to `console`.
256
+ * Logger used for queue diagnostics.
257
+ *
258
+ * @defaultValue console
247
259
  *
248
260
  * @remarks
249
261
  * Connection lifecycle messages and all internal errors are written here
@@ -252,7 +264,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
252
264
  */
253
265
  logger?: ILogger;
254
266
  /**
255
- * Interval in milliseconds of the periodic watcher check. Defaults to 5000.
267
+ * Interval in milliseconds of the periodic watcher check.
268
+ *
269
+ * @defaultValue 5000
256
270
  *
257
271
  * @remarks
258
272
  * Each tick re-elects a watcher owner if none exists and, on
@@ -260,6 +274,14 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
260
274
  * fallback when Redis keyspace notifications are unavailable. That makes this
261
275
  * value the worst-case extra latency for a delayed message. Setting it to `0`
262
276
  * disables both behaviours.
277
+ *
278
+ * It also paces the watcher's maintenance sweep, which recovers the
279
+ * messages of workers that have died and drives the
280
+ * {@link IMQOptions.cleanup} pass — so this, not
281
+ * {@link IMQOptions.safeDeliveryTtl}, is the worst-case latency for a
282
+ * crashed worker's message coming back. With the check disabled the sweep
283
+ * falls back to `safeDeliveryTtl`, which on a large budget is very slow;
284
+ * leave it on if safe delivery matters.
263
285
  */
264
286
  watcherCheckDelay?: number;
265
287
  /**
@@ -271,8 +293,9 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
271
293
  * Must be set identically on every producer and consumer of a queue: a
272
294
  * mismatch makes deserialization fail, which emits an `error` event with the
273
295
  * event name `OnMessage` and drops the message — permanently, even under
274
- * {@link IMQOptions.safeDelivery}, because the worker key is released
275
- * immediately afterwards.
296
+ * {@link IMQOptions.safeDelivery}: a message that cannot be unpacked reaches
297
+ * no listener, so nothing is pending on it and its lease is released at
298
+ * once. Re-delivering it would only fail the same way.
276
299
  *
277
300
  * Applies to queue messages only. {@link IMessageQueue.publish} and
278
301
  * {@link IMessageQueue.subscribe} payloads are always plain JSON.
@@ -285,42 +308,58 @@ export interface IMQOptions extends Partial<IMessageQueueConnection> {
285
308
  * message leaves that message behind for the watcher to re-queue rather
286
309
  * than taking it down with the process.
287
310
  *
288
- * The guarantee covers that hand-off, not the processing. The worker key
289
- * is released as soon as the message is dispatched to the `message`
290
- * listener, so a worker killed while its handler is still running loses
291
- * that message exactly as it would with safe delivery off — draining
292
- * in-flight work before exit is up to the application. Delivery is
293
- * at-least-once in either mode, so handlers should be idempotent.
311
+ * The guarantee covers the processing too, not only the hand-off: the
312
+ * worker key is held until the `message` listener has finished with the
313
+ * message, which for a listener returning a promise means until that
314
+ * promise settles. A worker killed at any point before then leaves the
315
+ * message behind to be re-queued.
316
+ *
317
+ * A message comes back on either of two counts. The owning process leaving
318
+ * the broker's client list catches it dying — a fact the broker holds
319
+ * rather than an inference from a clock, so it is noticed as fast as the
320
+ * socket closes and nothing has to be renewed to keep a live lease alive.
321
+ * {@link IMQOptions.safeDeliveryTtl} catches what liveness cannot see: one
322
+ * handler wedged inside a worker that is otherwise up and serving.
323
+ *
324
+ * Delivery is at-least-once in either mode, so handlers should be
325
+ * idempotent: this narrows the window in which in-flight work is lost, it
326
+ * does not close it.
294
327
  *
295
328
  * @defaultValue false
296
329
  */
297
330
  safeDelivery?: boolean;
298
331
  /**
299
- * Lease deadline (in milliseconds) stamped onto the worker key when
300
- * safeDelivery moves a message out of the queue, and the interval on which
301
- * the watcher sweeps for expired keys. A worker key still present once its
302
- * deadline has passed is treated as abandoned, and its message is moved
303
- * back onto the main queue.
332
+ * The longest (in milliseconds) a message may be worked on before it is
333
+ * treated as abandoned and moved back onto the queue.
304
334
  *
305
- * This is a recovery deadline for an abandoned hand-off, not a processing
306
- * deadline. The key is released when the message is dispatched, so a slow
307
- * handler is neither interrupted nor re-queued for taking too long, and
308
- * raising this value extends no protection over long-running work — tune it
309
- * for how quickly an abandoned message should come back.
310
- *
311
- * @defaultValue 5000
335
+ * @defaultValue 300000
312
336
  *
313
337
  * @remarks
314
- * This value applies whether or not {@link IMQOptions.safeDelivery} is on:
315
- * it always sets the period of the watcher's maintenance sweep, which also
316
- * drives the {@link IMQOptions.cleanup} pass. Setting it to `null` or
317
- * `undefined` disables that interval altogether, so neither lease recovery
318
- * nor cleanup runs.
319
- *
320
- * In safe-delivery mode it additionally sets the reader's blocking-pop
321
- * timeout to half the TTL, with a 100 ms floor, after which the reader
322
- * regenerates the lease and blocks again. Very small values therefore
323
- * increase Redis round-trips without further reducing latency.
338
+ * Set it to the longest a handler in this system can legitimately take,
339
+ * with headroom. A slow upstream is the usual reason for a large value — a
340
+ * data vendor with no job API, screen-scraping behind an HTTP call,
341
+ * anything that can take minutes — and a budget below that reclaims a
342
+ * message from a worker still legitimately working on it, handing somebody
343
+ * else a duplicate.
344
+ *
345
+ * This is the **only** thing that recovers a message from a worker that is
346
+ * alive, connected and serving other messages while one handler has wedged
347
+ * on this one. Death of the whole process is caught separately and far
348
+ * faster, by the owner leaving the broker's client list, so this value does
349
+ * not govern how quickly an ordinary crash is recovered from.
350
+ *
351
+ * Two internals follow this value but deliberately do not scale with it:
352
+ *
353
+ * - The watcher's maintenance sweep — which recovers abandoned leases and
354
+ * drives the {@link IMQOptions.cleanup} pass — runs on
355
+ * {@link IMQOptions.watcherCheckDelay}, so a dead worker is still noticed
356
+ * within seconds however generous the budget is. Setting this to `null`
357
+ * or `undefined` disables that sweep altogether, so neither lease
358
+ * recovery nor cleanup runs.
359
+ * - The reader's blocking pop is half this value capped at 5000 ms, with a
360
+ * 100 ms floor. The cap matters: a lease deadline is stamped before the
361
+ * pop that fills the key, so an uncapped wait would hand a message a
362
+ * sizeable part of its budget already spent.
324
363
  */
325
364
  safeDeliveryTtl?: number;
326
365
  /**
@@ -397,6 +436,20 @@ export interface EventMap {
397
436
  /**
398
437
  * Emitted for every message consumed from the queue, with the payload, the
399
438
  * message id, and the name of the queue that sent it.
439
+ *
440
+ * @remarks
441
+ * Under {@link IMQOptions.safeDelivery} the value a listener **returns**
442
+ * decides when the message counts as handled. Return a promise and the
443
+ * message stays checked out until it settles, so a worker that dies
444
+ * mid-handler leaves it behind to be re-queued. Return anything else and it
445
+ * is released as the listener returns, which is all a synchronous handler
446
+ * can offer — and is also how to opt out, by starting the work and
447
+ * returning nothing.
448
+ *
449
+ * Every registered listener is consulted, and the message is released once
450
+ * all the promises they returned have settled — settled, not fulfilled: a
451
+ * handler that throws has still had its turn, and re-delivering on a
452
+ * rejection would retry a poison message forever.
400
453
  */
401
454
  message: [data: JsonObject, id: string, from: string];
402
455
  /**
@@ -636,9 +689,11 @@ export interface IMessageQueue extends EventEmitter<EventMap> {
636
689
  *
637
690
  * @remarks
638
691
  * Other queues in the namespace, the watcher lock, and messages currently
639
- * leased to a worker under {@link IMQOptions.safeDelivery} are all untouched —
640
- * a leased message can be re-queued by the watcher once its lease expires, so
641
- * this does not guarantee the queue stays empty.
692
+ * checked out to a worker under {@link IMQOptions.safeDelivery} are all
693
+ * untouched — such a message returns to the queue if its worker dies or
694
+ * overruns {@link IMQOptions.safeDeliveryTtl}, so this does not guarantee
695
+ * the queue stays empty. A message is checked out for as long as its
696
+ * handler runs, so that window is as long as your slowest handler.
642
697
  *
643
698
  * It never rejects: with no writer connection it silently does nothing, and
644
699
  * host failures are logged rather than raised, so success cannot be inferred
@@ -651,9 +706,11 @@ export interface IMessageQueue extends EventEmitter<EventMap> {
651
706
  * @returns count of messages waiting to be consumed
652
707
  *
653
708
  * @remarks
654
- * Delayed messages that are not yet due, and messages currently leased to a
655
- * worker under {@link IMQOptions.safeDelivery}, are not counted — so this
656
- * is not the amount of outstanding work.
709
+ * Delayed messages that are not yet due, and messages currently checked out
710
+ * to a worker under {@link IMQOptions.safeDelivery}, are not counted — so
711
+ * this is not the amount of outstanding work. Under safe delivery a message
712
+ * is checked out for as long as its handler runs, so on a busy queue the
713
+ * shortfall is roughly everything in flight, not a rounding error.
657
714
  *
658
715
  * Returns `0` when the queue has no writer connection, which makes
659
716
  * "disconnected" indistinguishable from "empty".
@@ -107,6 +107,14 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
107
107
  * consuming the key it was started with.
108
108
  */
109
109
  name: string;
110
+ /**
111
+ * Whether this handle publishes, consumes, or both.
112
+ *
113
+ * @remarks
114
+ * Fixed at construction: it decides which connections `start()` opens,
115
+ * so a publisher never opens a reader and cannot consume even by
116
+ * accident.
117
+ */
110
118
  private readonly mode;
111
119
  /**
112
120
  * Writer connections collection
@@ -202,6 +210,8 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
202
210
  * removing their keys.
203
211
  */
204
212
  private lastConnectedKeys;
213
+ /** Lease owners seen connected on the previous sweep (one sweep of grace) */
214
+ private lastOwners;
205
215
  /**
206
216
  * True while this instance holds a reference to the shared writer
207
217
  */
@@ -210,7 +220,18 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
210
220
  * Internal per-channel reconnection state
211
221
  */
212
222
  private reconnectTimers;
223
+ /**
224
+ * Consecutive failed reconnection attempts per channel, which is what the
225
+ * backoff delay is computed from. Reset once a channel connects again.
226
+ */
213
227
  private reconnectAttempts;
228
+ /**
229
+ * Channels with a reconnection already in progress.
230
+ *
231
+ * @remarks
232
+ * A guard, not a status: several `close` events can arrive for one channel,
233
+ * and without this each would start its own reconnection loop.
234
+ */
214
235
  private reconnecting;
215
236
  /**
216
237
  * The `host:port` address of the redis server this queue talks to.
@@ -231,13 +252,18 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
231
252
  /**
232
253
  * Serializes a given data object into string
233
254
  *
234
- * @param data -
255
+ * @param data - the value to serialize; must be JSON-serializable
256
+ * @returns the wire representation, gzipped when
257
+ * {@link IMQOptions.useGzip} is on
235
258
  */
236
259
  private readonly pack;
237
260
  /**
238
261
  * Deserialize string data into an object
239
262
  *
240
- * @param data -
263
+ * @param data - the wire representation, as produced by `pack`
264
+ * @returns the deserialized value
265
+ * @throws when the payload is malformed, or was packed with a different
266
+ * {@link IMQOptions.useGzip} setting
241
267
  */
242
268
  private readonly unpack;
243
269
  /**
@@ -268,7 +294,25 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
268
294
  * Assign it before {@link RedisQueue.start} — a running reader keeps
269
295
  * consuming the key it was started with.
270
296
  */
271
- name: string, options?: Partial<IMQOptions>, mode?: IMQMode);
297
+ name: string, options?: Partial<IMQOptions>,
298
+ /**
299
+ * Whether this handle publishes, consumes, or both.
300
+ *
301
+ * @remarks
302
+ * Fixed at construction: it decides which connections `start()` opens,
303
+ * so a publisher never opens a reader and cannot consume even by
304
+ * accident.
305
+ */
306
+ mode?: IMQMode);
307
+ /**
308
+ * Writes a diagnostic line, but only under {@link IMQOptions.verbose}.
309
+ *
310
+ * @param message - the line to write, tagged with this queue's name
311
+ *
312
+ * @remarks
313
+ * For tracing the queue's own lifecycle. Anything a user must see whether
314
+ * or not verbose is on goes through `logLine` instead.
315
+ */
272
316
  private verbose;
273
317
  /**
274
318
  * Writes an unconditional line through this queue's logger, in the format
@@ -328,8 +372,8 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
328
372
  * Attaches a subscription message handler to a given channel
329
373
  * connection
330
374
  *
331
- * @param chan -
332
- * @param handler -
375
+ * @param chan - the pub/sub channel to deliver messages from
376
+ * @param handler - called with the decoded payload of each message
333
377
  */
334
378
  private attachSubscriptionHandler;
335
379
  /**
@@ -493,9 +537,11 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
493
537
  * and silently discarded.
494
538
  *
495
539
  * With `clearData` set, only the main and delayed keys are removed: messages
496
- * currently leased to a worker key under {@link IMQOptions.safeDelivery} are
497
- * not, and the watcher will re-queue them once their lease expires — so
498
- * messages can reappear after a clearing destroy.
540
+ * currently checked out to a worker key under
541
+ * {@link IMQOptions.safeDelivery} are not, and the watcher returns them to
542
+ * the queue once their worker is gone or their
543
+ * {@link IMQOptions.safeDeliveryTtl} is spent — so messages can reappear
544
+ * after a clearing destroy.
499
545
  *
500
546
  * Never rejects; unlock and clear failures are logged.
501
547
  */
@@ -508,9 +554,10 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
508
554
  * @remarks
509
555
  * A no-op that resolves successfully when the queue has no writer connection.
510
556
  * In-flight messages held in worker keys under
511
- * {@link IMQOptions.safeDelivery} are not removed and may be re-queued by the
512
- * watcher after their lease expires, so this does not guarantee the queue
513
- * stays empty. Errors are logged rather than thrown, so success cannot be
557
+ * {@link IMQOptions.safeDelivery} are not removed, and the watcher returns
558
+ * them to the queue once their worker is gone or their
559
+ * {@link IMQOptions.safeDeliveryTtl} is spent — so this does not guarantee
560
+ * the queue stays empty. Errors are logged rather than thrown, so success cannot be
514
561
  * inferred from a resolved promise.
515
562
  */
516
563
  clear(): Promise<RedisQueue>;
@@ -520,11 +567,14 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
520
567
  * @returns count of messages waiting to be consumed
521
568
  *
522
569
  * @remarks
523
- * Delayed messages that are not yet due, and messages currently leased to a
524
- * worker under {@link IMQOptions.safeDelivery}, are not counted — so this
525
- * is not the amount of outstanding work. Returns `0` when the queue has no
526
- * writer connection, which makes "disconnected" indistinguishable from
527
- * "empty"; it never throws.
570
+ * Delayed messages that are not yet due, and messages currently checked out
571
+ * to a worker under {@link IMQOptions.safeDelivery}, are not counted — so
572
+ * this is not the amount of outstanding work. Under safe delivery a message
573
+ * is checked out for as long as its handler runs, so on a busy queue the
574
+ * shortfall is roughly everything in flight, not a rounding error.
575
+ *
576
+ * Returns `0` when the queue has no writer connection, which makes
577
+ * "disconnected" indistinguishable from "empty"; it never throws.
528
578
  */
529
579
  queueLength(): Promise<number>;
530
580
  /**
@@ -564,14 +614,15 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
564
614
  /**
565
615
  * Returns the connection currently bound to the given channel, if any.
566
616
  *
567
- * @param channel -
617
+ * @param channel - which of the queue's connections to look up
618
+ * @returns the connection, or `undefined` when that channel is not open
568
619
  */
569
620
  private connectionOf;
570
621
  /**
571
622
  * Binds the given connection to the given channel.
572
623
  *
573
- * @param channel -
574
- * @param conn -
624
+ * @param channel - which of the queue's connections to bind
625
+ * @param conn - the client to bind, or `undefined` to unbind it
575
626
  */
576
627
  private bindConnection;
577
628
  /**
@@ -601,15 +652,16 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
601
652
  /**
602
653
  * Establishes a given connection channel by its name
603
654
  *
604
- * @param channel -
605
- * @param options -
655
+ * @param channel - which of the queue's connections to open
656
+ * @param options - connection options; falls back to this queue's own
657
+ * @returns the ready client
606
658
  */
607
659
  private connect;
608
660
  /**
609
661
  * Schedules custom reconnection for a given channel with capped
610
662
  * exponential backoff
611
663
  *
612
- * @param channel -
664
+ * @param channel - which of the queue's connections to reconnect
613
665
  */
614
666
  private scheduleReconnect;
615
667
  /**
@@ -617,33 +669,50 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
617
669
  * rescheduling itself on failure. Errors are handled internally, so the
618
670
  * scheduled timer never produces an unhandled rejection.
619
671
  *
620
- * @param channel -
672
+ * @param channel - which of the queue's connections to reconnect
621
673
  */
622
674
  private reconnectNow;
623
675
  /**
624
676
  * Generates channel name
625
677
  *
626
- * @param contextName -
627
- * @param prefix -
628
- * @param name -
678
+ * @param contextName - the queue name the connection belongs to
679
+ * @param prefix - the key prefix this queue works under
680
+ * @param name - which of the queue's connections this is
681
+ * @returns the name registered with the broker, ending in this process's
682
+ * pid and host — which is what makes a connection, and so a lease
683
+ * owner, identifiable in `CLIENT LIST`
629
684
  */
630
685
  private getChannelName;
631
686
  /**
632
687
  * Builds and returns connection error handler
633
688
  *
634
- * @param channel -
689
+ * @param channel - which of the queue's connections the handler is for
690
+ * @returns the handler to attach to that connection's `error` event
635
691
  */
636
692
  private onErrorHandler;
637
693
  /**
638
694
  * Builds and returns redis connection close handler
639
695
  *
640
- * @param channel -
696
+ * @param channel - which of the queue's connections the handler is for
697
+ * @returns the handler to attach to that connection's `close` event
641
698
  */
642
699
  private onCloseHandler;
643
700
  /**
644
- * Processes given redis-queue message
701
+ * Unpacks one raw queue message and hands it to the `message` listeners.
702
+ *
703
+ * @param msg - the `[queue key, packed message]` pair as read off redis
704
+ * @returns the promises the listeners returned, empty when none did
645
705
  *
646
- * @param msg -
706
+ * @remarks
707
+ * The return value is how the caller learns when the listeners are actually
708
+ * finished, which is what {@link RedisQueue.readSafe} needs in order to know
709
+ * when a message's lease may be dropped. `emit()` discards what a listener
710
+ * returns, so the listeners are invoked directly; raw listeners are used so
711
+ * a `once` listener still removes itself and still yields its value, exactly
712
+ * as `emit()` would have arranged.
713
+ *
714
+ * A listener throwing synchronously propagates, as it does through `emit()`.
715
+ * An unreadable message dispatches nothing and reports nothing pending.
647
716
  */
648
717
  private process;
649
718
  /**
@@ -651,26 +720,63 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
651
720
  */
652
721
  private watcherCount;
653
722
  /**
654
- * Processes delayed a message by its given redis key
723
+ * Moves messages whose delay has elapsed onto their queue.
655
724
  *
656
- * @param key -
725
+ * @param key - the queue key whose `:delayed` companion to drain
657
726
  */
658
727
  private processDelayed;
659
728
  /**
660
- * Watch routine
729
+ * Sweeps for leases whose worker is not coming back and returns their
730
+ * messages to the queue.
731
+ *
732
+ * @param clients - raw `CLIENT LIST` output for this tick, or `undefined`
733
+ * when it could not be read, in which case liveness is unknown and a
734
+ * lease is left to its budget rather than guessed at
661
735
  */
662
736
  private processWatch;
663
737
  /**
664
- * Process given keys from a message queue
738
+ * Decides whether one worker key has been abandoned.
665
739
  *
666
- * @param keys -
667
- * @param now -
740
+ * @param key - the worker key
741
+ * @param now - the timestamp this sweep started at
742
+ * @param owners - processes currently connected, or `undefined` when the
743
+ * client list could not be read
744
+ * @returns whether this key's message should go back on the queue
745
+ *
746
+ * @remarks
747
+ * Which scheme applies is read off the key itself rather than off this
748
+ * queue's options, because the sweeper serves every queue sharing the
749
+ * prefix and they need not be configured alike.
750
+ *
751
+ * A key naming its owner is abandoned on either of two counts, because
752
+ * there are two ways to lose a message. The owner having left the broker's
753
+ * client list catches the process dying — the common case, detected as fast
754
+ * as the socket closes and needing nothing renewed to keep a live lease
755
+ * alive. The deadline catches what liveness cannot see: a worker that is up,
756
+ * connected and serving other messages while one handler has wedged on this
757
+ * one. The budget is honoured even when liveness is unknown, since an
758
+ * exhausted budget is exhausted either way.
759
+ *
760
+ * A key with no owner was written by 3.x, before leases named one. Its
761
+ * deadline is the whole story, exactly as it was then, so a rolling upgrade
762
+ * does not strand it.
763
+ */
764
+ private isAbandoned;
765
+ /**
766
+ * Returns the messages of abandoned leases to their queues.
767
+ *
768
+ * @param keys - worker keys from one page of the sweep's `SCAN`
769
+ * @param now - the timestamp the sweep started at, so every key in a pass
770
+ * is judged against the same instant
771
+ * @param owners - processes currently connected, or `undefined` when the
772
+ * client list could not be read
668
773
  */
669
774
  private processKeys;
670
775
  /**
671
- * Watch message processor
776
+ * Handles one keyspace notification from the watcher subscription.
672
777
  *
673
- * @param args -
778
+ * @param args - the `pmessage` arguments; only the last, the expired key,
779
+ * is used, and only when it is a delayed message's ttl marker
674
780
  */
675
781
  private onWatchMessage;
676
782
  /**
@@ -719,13 +825,60 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
719
825
  */
720
826
  private runSafeCheck;
721
827
  /**
722
- * Cleans up orphaned keys from redis
828
+ * Reads the broker's client list.
829
+ *
830
+ * @returns the raw `CLIENT LIST` output, or `undefined` when it could not
831
+ * be read
832
+ *
833
+ * @remarks
834
+ * A failure must not read as "nobody is connected" — that would reclaim
835
+ * every lease in flight and delete every key in the prefix — so it is
836
+ * reported as unknown rather than as an empty list.
837
+ */
838
+ private readClients;
839
+ /**
840
+ * Extracts the processes currently connected to the broker, as the owner
841
+ * tokens stamped into worker keys.
842
+ *
843
+ * @param clients - raw `CLIENT LIST` output
844
+ * @returns owners seen connected now, plus those seen on the previous sweep
845
+ *
846
+ * @remarks
847
+ * Previous-sweep owners are included deliberately, mirroring the grace the
848
+ * cleanup pass already gives reconnecting clients: a worker riding out a
849
+ * reconnect backoff briefly leaves the client list, and reclaiming its
850
+ * leases then would re-deliver work that is still running. One sweep of
851
+ * grace costs one sweep of recovery latency and removes that whole class of
852
+ * duplicate.
853
+ */
854
+ private connectedOwners;
855
+ /**
856
+ * Removes keys left behind by clients that are no longer connected.
857
+ *
858
+ * @param clients - raw `CLIENT LIST` output for this tick, so the list is
859
+ * read once per sweep. Called on its own, this reads its own; a read
860
+ * that fails throws into the catch below and deletes nothing,
861
+ * because treating an unreadable list as "no client owns anything"
862
+ * would delete every key in the prefix
863
+ * @returns this queue instance, or `undefined` when cleanup is disabled
723
864
  */
724
865
  private processCleanup;
725
866
  /**
726
867
  * Unreliable but fast way of message handling by the queue
727
868
  */
728
869
  private readUnsafe;
870
+ /**
871
+ * Ends one lease, dropping the worker key and with it the message.
872
+ *
873
+ * @param workerKey - the key holding the message
874
+ *
875
+ * @remarks
876
+ * Idempotent, and never throws: an undeleted worker key is re-queued by the
877
+ * watcher later, which is one of the causes a handler can be given for a
878
+ * duplicate. The key itself is never logged, as it carries the queue name
879
+ * and the lease id.
880
+ */
881
+ private releaseLease;
729
882
  /**
730
883
  * Reliable but slow method of message handling by message queue.
731
884
  *
@@ -754,9 +907,10 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
754
907
  /**
755
908
  * Emits error
756
909
  *
757
- * @param eventName -
758
- * @param message -
759
- * @param err -
910
+ * @param eventName - the internal routine that caught it, used as a
911
+ * diagnostic label such as `OnMessage` or `OnReadSafe`
912
+ * @param message - human-readable context for the log line
913
+ * @param err - the caught value, wrapped when it is not an `Error`
760
914
  */
761
915
  private emitError;
762
916
  /**