@my-nestjs-kit/queues 0.0.0-stage → 0.1.0-dev.20261129020438

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -2
  3. package/dist/decorators/index.d.ts +2 -0
  4. package/dist/decorators/index.js +18 -0
  5. package/dist/decorators/processor-meta.decorator.d.ts +10 -0
  6. package/dist/decorators/processor-meta.decorator.js +19 -0
  7. package/dist/decorators/queue-service.decorator.d.ts +11 -0
  8. package/dist/decorators/queue-service.decorator.js +15 -0
  9. package/dist/dynamic-queues/dynamic-queue-names.d.ts +12 -0
  10. package/dist/dynamic-queues/dynamic-queue-names.js +49 -0
  11. package/dist/dynamic-queues/dynamic-queue-processor.decorator.d.ts +23 -0
  12. package/dist/dynamic-queues/dynamic-queue-processor.decorator.js +29 -0
  13. package/dist/dynamic-queues/dynamic-queue-processors.explorer.d.ts +12 -0
  14. package/dist/dynamic-queues/dynamic-queue-processors.explorer.js +57 -0
  15. package/dist/dynamic-queues/dynamic-queues-channel.d.ts +21 -0
  16. package/dist/dynamic-queues/dynamic-queues-channel.js +55 -0
  17. package/dist/dynamic-queues/dynamic-queues-factory.d.ts +88 -0
  18. package/dist/dynamic-queues/dynamic-queues-factory.js +162 -0
  19. package/dist/dynamic-queues/dynamic-queues-module.options.d.ts +76 -0
  20. package/dist/dynamic-queues/dynamic-queues-module.options.js +2 -0
  21. package/dist/dynamic-queues/dynamic-queues-state.d.ts +79 -0
  22. package/dist/dynamic-queues/dynamic-queues-state.js +142 -0
  23. package/dist/dynamic-queues/dynamic-queues.constants.d.ts +10 -0
  24. package/dist/dynamic-queues/dynamic-queues.constants.js +14 -0
  25. package/dist/dynamic-queues/dynamic-queues.manager.d.ts +85 -0
  26. package/dist/dynamic-queues/dynamic-queues.manager.js +404 -0
  27. package/dist/dynamic-queues/dynamic-queues.module.d.ts +16 -0
  28. package/dist/dynamic-queues/dynamic-queues.module.js +76 -0
  29. package/dist/dynamic-queues/dynamic-queues.registry.d.ts +18 -0
  30. package/dist/dynamic-queues/dynamic-queues.registry.js +55 -0
  31. package/dist/dynamic-queues/dynamic-queues.types.d.ts +81 -0
  32. package/dist/dynamic-queues/dynamic-queues.types.js +2 -0
  33. package/dist/dynamic-queues/index.d.ts +13 -0
  34. package/dist/dynamic-queues/index.js +33 -0
  35. package/dist/dynamic-queues/proxy-queues.binder.d.ts +17 -0
  36. package/dist/dynamic-queues/proxy-queues.binder.js +63 -0
  37. package/dist/index.d.ts +10 -0
  38. package/dist/index.js +30 -0
  39. package/dist/jobs.types.d.ts +4 -0
  40. package/dist/jobs.types.js +2 -0
  41. package/dist/middlewares/middlewares.types.d.ts +10 -0
  42. package/dist/middlewares/middlewares.types.js +6 -0
  43. package/dist/process/index.d.ts +1 -0
  44. package/dist/process/index.js +17 -0
  45. package/dist/process/process.decorator.d.ts +13 -0
  46. package/dist/process/process.decorator.js +45 -0
  47. package/dist/processor-base.abstract.d.ts +39 -0
  48. package/dist/processor-base.abstract.js +125 -0
  49. package/dist/queue-service.base.d.ts +28 -0
  50. package/dist/queue-service.base.js +73 -0
  51. package/dist/queues.constants.d.ts +3 -0
  52. package/dist/queues.constants.js +6 -0
  53. package/dist/queues.module.d.ts +11 -0
  54. package/dist/queues.module.js +58 -0
  55. package/dist/queues.types.d.ts +99 -0
  56. package/dist/queues.types.js +57 -0
  57. package/dist/types/index.d.ts +17 -0
  58. package/dist/types/index.js +2 -0
  59. package/package.json +102 -3
@@ -0,0 +1,76 @@
1
+ import type { Job } from 'bullmq';
2
+ import type { DynamicQueueOptions, DynamicQueuesFactory, DynamicWorkerOptions } from './dynamic-queues-factory';
3
+ import type { DynamicQueuesStateStore } from './dynamic-queues-state';
4
+ import type { DefaultDynamicQueuesMap, DynamicJobContext, DynamicQueueRef, DynamicQueueType, DynamicQueuesMap, DynamicQueuesWorkersPolicy } from './dynamic-queues.types';
5
+ /** Why a queue started / stopped on this instance. */
6
+ export type DynamicQueueStartReason = 'start' | 'takeover' | 'restore' | 'remote';
7
+ export type DynamicQueueStopReason = 'stop' | 'idle' | 'remote' | 'lost';
8
+ /**
9
+ * Lifecycle and job hooks (monitoring, alerts, SSE bridges). Errors thrown here are logged and
10
+ * swallowed; they never fail a job.
11
+ */
12
+ export interface DynamicQueuesHooks {
13
+ onQueueStarted?(ref: DynamicQueueRef, reason: DynamicQueueStartReason): unknown;
14
+ onQueuePaused?(ref: DynamicQueueRef, reason: 'pause' | 'remote'): unknown;
15
+ onQueueStopped?(ref: DynamicQueueRef, reason: DynamicQueueStopReason): unknown;
16
+ onJobCompleted?(ref: DynamicQueueRef, job: Job, result: unknown): unknown;
17
+ /** Every failed attempt; `exhausted` = no retries left. */
18
+ onJobFailed?(ref: DynamicQueueRef, job: Job, error: Error, exhausted: boolean): unknown;
19
+ }
20
+ export interface DynamicQueuesModuleOptions {
21
+ factory: DynamicQueuesFactory;
22
+ state: DynamicQueuesStateStore;
23
+ /** This instance in the leases. Default `<hostname>:<pid>:<random>`. */
24
+ serverId?: string;
25
+ /**
26
+ * `starter` (default): a worker runs only on the instance that started / took over the queue.
27
+ * `all`: every instance runs one once any instance starts it.
28
+ */
29
+ workers?: DynamicQueuesWorkersPolicy;
30
+ /**
31
+ * On bootstrap start local workers for every active queue (not only stale ones). Default false.
32
+ * With `starter` this makes every booting instance a worker of every active queue — usually
33
+ * you want the lease takeover instead (`takeover`, on by default).
34
+ */
35
+ restoreOnBoot?: boolean;
36
+ /** A lease not renewed for this long is stale and taken over. Default 30s. */
37
+ leaseTtlMs?: number;
38
+ /** Heartbeat / takeover / idle-check period. Default 10s; 0 = no timer (call `tick()` yourself). */
39
+ heartbeatMs?: number;
40
+ /** Take over active queues whose owner stopped heartbeating. Default true. */
41
+ takeover?: boolean;
42
+ /** Max workers this instance runs; `start()` throws and takeover skips beyond it. */
43
+ maxLocalWorkers?: number;
44
+ /** How long shutdown waits for active jobs before force-closing workers. Default 10s. */
45
+ shutdownTimeoutMs?: number;
46
+ hooks?: DynamicQueuesHooks;
47
+ /**
48
+ * Bind a `proxy__<type>` queue to every `@QueueService({ hasProxy: true })` provider on
49
+ * bootstrap. Default false.
50
+ */
51
+ bindProxies?: boolean;
52
+ }
53
+ export interface DynamicQueuesModuleAsyncOptions {
54
+ imports?: any[];
55
+ inject?: any[];
56
+ useFactory: (...args: any[]) => DynamicQueuesModuleOptions | Promise<DynamicQueuesModuleOptions>;
57
+ }
58
+ /**
59
+ * Per-type options, registered by the module that owns the type (`forFeature`). Retries /
60
+ * backoff go to `queueOptions.defaultJobOptions`; concurrency and BullMQ's per-queue rate limit
61
+ * (`limiter`) to `workerOptions`.
62
+ */
63
+ export interface DynamicQueueTypeConfig<M extends DynamicQueuesMap = DefaultDynamicQueuesMap> {
64
+ type: DynamicQueueType<M>;
65
+ queueOptions?: DynamicQueueOptions;
66
+ workerOptions?: DynamicWorkerOptions;
67
+ /** Rejects ids before a queue is created: return false or an error message. */
68
+ validateId?(id: string): boolean | string;
69
+ /**
70
+ * The owner stops a queue with no activity for this long and nothing waiting / delayed /
71
+ * active in it. Off by default.
72
+ */
73
+ idleTimeoutMs?: number;
74
+ /** A job failed its last attempt (dead-letter it, alert…). */
75
+ onExhausted?(job: Job, error: Error, ctx: DynamicJobContext): unknown;
76
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,79 @@
1
+ import type Redis from 'ioredis';
2
+ /** One active queue in the cluster state: who runs it and when it last said so. */
3
+ export interface DynamicQueueLease {
4
+ name: string;
5
+ /** serverId of the instance that started (or took over) the queue. */
6
+ owner?: string;
7
+ /** Epoch ms of the owner's last heartbeat; 0 = released (free to take over at once). */
8
+ heartbeatAt: number;
9
+ }
10
+ /**
11
+ * Cluster-wide state of dynamic queues: a lease per active queue (owner + heartbeat), so a
12
+ * queue whose owner died is taken over, plus a short lock so two instances don't flip the same
13
+ * queue at once. Times are the callers' clocks (epoch ms).
14
+ */
15
+ export interface DynamicQueuesStateStore {
16
+ /** Marks the queue active, owned by `owner`, heartbeat = `now`. Overrides a previous owner. */
17
+ activate(name: string, owner: string, now: number): Promise<void>;
18
+ deactivate(name: string): Promise<void>;
19
+ /**
20
+ * Sets the heartbeat of the queues still owned by `owner` to `at` (0 releases them);
21
+ * resolves the names no longer owned by `owner` (taken over or deactivated).
22
+ */
23
+ heartbeat(names: string[], owner: string, at: number): Promise<string[]>;
24
+ /** Takes the queue over when it's active and its heartbeat is older than `staleBefore` (or it's ours). */
25
+ claim(name: string, owner: string, now: number, staleBefore: number): Promise<boolean>;
26
+ isActive(name: string): Promise<boolean>;
27
+ list(): Promise<DynamicQueueLease[]>;
28
+ /** Runs `fn` under the lock; resolves undefined without running it when the lock is taken. */
29
+ withLock<R>(key: string, fn: () => Promise<R>): Promise<R | undefined>;
30
+ }
31
+ /** Single-process store, for tests and single-instance apps. Share one instance between "instances" in tests. */
32
+ export declare class InMemoryDynamicQueuesStateStore implements DynamicQueuesStateStore {
33
+ private readonly leases;
34
+ private readonly locks;
35
+ activate(name: string, owner: string, now: number): Promise<void>;
36
+ deactivate(name: string): Promise<void>;
37
+ heartbeat(names: string[], owner: string, at: number): Promise<string[]>;
38
+ claim(name: string, owner: string, now: number, staleBefore: number): Promise<boolean>;
39
+ isActive(name: string): Promise<boolean>;
40
+ list(): Promise<{
41
+ name: string;
42
+ /** serverId of the instance that started (or took over) the queue. */
43
+ owner?: string;
44
+ /** Epoch ms of the owner's last heartbeat; 0 = released (free to take over at once). */
45
+ heartbeatAt: number;
46
+ }[]>;
47
+ withLock<R>(key: string, fn: () => Promise<R>): Promise<R>;
48
+ }
49
+ export interface RedisDynamicQueuesStateOptions {
50
+ /**
51
+ * Sorted set of active queue names, score = heartbeat; owners live in the hash `<key>:owners`.
52
+ * Default `dynamic-queues:active`. Must not be a key of another Redis type (WRONGTYPE).
53
+ */
54
+ key?: string;
55
+ /** Default `dynamic-queues:lock:`. */
56
+ lockPrefix?: string;
57
+ lockTtlMs?: number;
58
+ }
59
+ /** ioredis store: a heartbeat zset + owners hash (one lease per queue) and `SET NX PX` locks. */
60
+ export declare class RedisDynamicQueuesStateStore implements DynamicQueuesStateStore {
61
+ private readonly redis;
62
+ static readonly scripts: {
63
+ RELEASE_LOCK: string;
64
+ HEARTBEAT: string;
65
+ CLAIM: string;
66
+ };
67
+ private readonly key;
68
+ private readonly ownersKey;
69
+ private readonly lockPrefix;
70
+ private readonly lockTtlMs;
71
+ constructor(redis: Redis, options?: RedisDynamicQueuesStateOptions);
72
+ activate(name: string, owner: string, now: number): Promise<void>;
73
+ deactivate(name: string): Promise<void>;
74
+ heartbeat(names: string[], owner: string, at: number): Promise<string[]>;
75
+ claim(name: string, owner: string, now: number, staleBefore: number): Promise<boolean>;
76
+ isActive(name: string): Promise<boolean>;
77
+ list(): Promise<DynamicQueueLease[]>;
78
+ withLock<R>(key: string, fn: () => Promise<R>): Promise<R>;
79
+ }
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisDynamicQueuesStateStore = exports.InMemoryDynamicQueuesStateStore = void 0;
4
+ const crypto_1 = require("crypto");
5
+ /** Single-process store, for tests and single-instance apps. Share one instance between "instances" in tests. */
6
+ class InMemoryDynamicQueuesStateStore {
7
+ constructor() {
8
+ this.leases = new Map();
9
+ this.locks = new Set();
10
+ }
11
+ async activate(name, owner, now) {
12
+ this.leases.set(name, { name, owner, heartbeatAt: now });
13
+ }
14
+ async deactivate(name) {
15
+ this.leases.delete(name);
16
+ }
17
+ async heartbeat(names, owner, at) {
18
+ const lost = [];
19
+ for (const name of names) {
20
+ const lease = this.leases.get(name);
21
+ if (lease?.owner === owner)
22
+ lease.heartbeatAt = at;
23
+ else
24
+ lost.push(name);
25
+ }
26
+ return lost;
27
+ }
28
+ async claim(name, owner, now, staleBefore) {
29
+ const lease = this.leases.get(name);
30
+ if (!lease)
31
+ return false;
32
+ if (lease.owner !== owner && lease.heartbeatAt >= staleBefore)
33
+ return false;
34
+ lease.owner = owner;
35
+ lease.heartbeatAt = now;
36
+ return true;
37
+ }
38
+ async isActive(name) {
39
+ return this.leases.has(name);
40
+ }
41
+ async list() {
42
+ return [...this.leases.values()].map((l) => ({ ...l }));
43
+ }
44
+ async withLock(key, fn) {
45
+ if (this.locks.has(key))
46
+ return undefined;
47
+ this.locks.add(key);
48
+ try {
49
+ return await fn();
50
+ }
51
+ finally {
52
+ this.locks.delete(key);
53
+ }
54
+ }
55
+ }
56
+ exports.InMemoryDynamicQueuesStateStore = InMemoryDynamicQueuesStateStore;
57
+ const RELEASE_LOCK = `if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end`;
58
+ // KEYS: zset, owners hash. ARGV: owner, at, ...names → names not owned by `owner`
59
+ const HEARTBEAT = `
60
+ local lost = {}
61
+ for i = 3, #ARGV do
62
+ local name = ARGV[i]
63
+ if redis.call("hget", KEYS[2], name) == ARGV[1] and redis.call("zscore", KEYS[1], name) then
64
+ redis.call("zadd", KEYS[1], ARGV[2], name)
65
+ else
66
+ table.insert(lost, name)
67
+ end
68
+ end
69
+ return lost`;
70
+ // KEYS: zset, owners hash. ARGV: name, owner, now, staleBefore → 1 when claimed
71
+ const CLAIM = `
72
+ local score = redis.call("zscore", KEYS[1], ARGV[1])
73
+ if not score then return 0 end
74
+ if redis.call("hget", KEYS[2], ARGV[1]) ~= ARGV[2] and tonumber(score) >= tonumber(ARGV[4]) then return 0 end
75
+ redis.call("hset", KEYS[2], ARGV[1], ARGV[2])
76
+ redis.call("zadd", KEYS[1], ARGV[3], ARGV[1])
77
+ return 1`;
78
+ /** ioredis store: a heartbeat zset + owners hash (one lease per queue) and `SET NX PX` locks. */
79
+ class RedisDynamicQueuesStateStore {
80
+ constructor(redis, options = {}) {
81
+ this.redis = redis;
82
+ this.key = options.key ?? 'dynamic-queues:active';
83
+ this.ownersKey = `${this.key}:owners`;
84
+ this.lockPrefix = options.lockPrefix ?? 'dynamic-queues:lock:';
85
+ this.lockTtlMs = options.lockTtlMs ?? 10_000;
86
+ }
87
+ async activate(name, owner, now) {
88
+ await this.redis
89
+ .multi()
90
+ .zadd(this.key, now, name)
91
+ .hset(this.ownersKey, name, owner)
92
+ .exec();
93
+ }
94
+ async deactivate(name) {
95
+ await this.redis
96
+ .multi()
97
+ .zrem(this.key, name)
98
+ .hdel(this.ownersKey, name)
99
+ .exec();
100
+ }
101
+ async heartbeat(names, owner, at) {
102
+ if (!names.length)
103
+ return [];
104
+ return (await this.redis.eval(HEARTBEAT, 2, this.key, this.ownersKey, owner, at, ...names));
105
+ }
106
+ async claim(name, owner, now, staleBefore) {
107
+ const res = await this.redis.eval(CLAIM, 2, this.key, this.ownersKey, name, owner, now, staleBefore);
108
+ return Number(res) === 1;
109
+ }
110
+ async isActive(name) {
111
+ return (await this.redis.zscore(this.key, name)) !== null;
112
+ }
113
+ async list() {
114
+ const [scores, owners] = await Promise.all([
115
+ this.redis.zrange(this.key, 0, -1, 'WITHSCORES'),
116
+ this.redis.hgetall(this.ownersKey),
117
+ ]);
118
+ const leases = [];
119
+ for (let i = 0; i < scores.length; i += 2)
120
+ leases.push({
121
+ name: scores[i],
122
+ heartbeatAt: Number(scores[i + 1]),
123
+ owner: owners?.[scores[i]],
124
+ });
125
+ return leases;
126
+ }
127
+ async withLock(key, fn) {
128
+ const lockKey = this.lockPrefix + key;
129
+ const token = (0, crypto_1.randomUUID)();
130
+ const ok = await this.redis.set(lockKey, token, 'PX', this.lockTtlMs, 'NX');
131
+ if (ok !== 'OK')
132
+ return undefined;
133
+ try {
134
+ return await fn();
135
+ }
136
+ finally {
137
+ await this.redis.eval(RELEASE_LOCK, 1, lockKey, token);
138
+ }
139
+ }
140
+ }
141
+ exports.RedisDynamicQueuesStateStore = RedisDynamicQueuesStateStore;
142
+ RedisDynamicQueuesStateStore.scripts = { RELEASE_LOCK, HEARTBEAT, CLAIM };
@@ -0,0 +1,10 @@
1
+ export declare const DYNAMIC_QUEUES_MODULE_OPTIONS: unique symbol;
2
+ export declare const DYNAMIC_JOB_HANDLER_METADATA = "nest-kit:dynamic-job-handler";
3
+ export declare const DYNAMIC_JOB_ANY = "*";
4
+ /** Kit channel the instances use to tell each other about dynamic queue changes. */
5
+ export declare const DYNAMIC_QUEUES_CHANNEL = "dynamic-queues";
6
+ export declare enum DynamicQueueEvent {
7
+ started = "started",
8
+ paused = "paused",
9
+ removed = "removed"
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicQueueEvent = exports.DYNAMIC_QUEUES_CHANNEL = exports.DYNAMIC_JOB_ANY = exports.DYNAMIC_JOB_HANDLER_METADATA = exports.DYNAMIC_QUEUES_MODULE_OPTIONS = void 0;
4
+ exports.DYNAMIC_QUEUES_MODULE_OPTIONS = Symbol('DYNAMIC_QUEUES_MODULE_OPTIONS');
5
+ exports.DYNAMIC_JOB_HANDLER_METADATA = 'nest-kit:dynamic-job-handler';
6
+ exports.DYNAMIC_JOB_ANY = '*';
7
+ /** Kit channel the instances use to tell each other about dynamic queue changes. */
8
+ exports.DYNAMIC_QUEUES_CHANNEL = 'dynamic-queues';
9
+ var DynamicQueueEvent;
10
+ (function (DynamicQueueEvent) {
11
+ DynamicQueueEvent["started"] = "started";
12
+ DynamicQueueEvent["paused"] = "paused";
13
+ DynamicQueueEvent["removed"] = "removed";
14
+ })(DynamicQueueEvent || (exports.DynamicQueueEvent = DynamicQueueEvent = {}));
@@ -0,0 +1,85 @@
1
+ import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
2
+ import type { Worker } from 'bullmq';
3
+ import { ChannelsPublisher } from '@my-nestjs-kit/channels';
4
+ import { DynamicQueueEvent } from './dynamic-queues.constants';
5
+ import type { DynamicQueuesModuleOptions } from './dynamic-queues-module.options';
6
+ import { DynamicQueuesRegistry } from './dynamic-queues.registry';
7
+ import type { DefaultDynamicQueuesMap, DynamicQueueHandle, DynamicQueueRef, DynamicQueueSnapshot, DynamicQueuesHealth, DynamicQueueType, DynamicQueuesMap, TypedDynamicQueue } from './dynamic-queues.types';
8
+ export interface StopDynamicQueueOptions {
9
+ /** Also delete the queue's BullMQ keys (jobs, repeatables) from Redis. */
10
+ obliterate?: boolean;
11
+ }
12
+ /**
13
+ * Owns this instance's dynamic queues (`dynamic__<type>__<id>`): producer handles, local
14
+ * workers, leases in the cluster state (heartbeat, takeover of dead owners, idle stop) and the
15
+ * `dynamic-queues` channel notifications.
16
+ */
17
+ export declare class DynamicQueuesManager<M extends DynamicQueuesMap = DefaultDynamicQueuesMap> implements OnApplicationBootstrap, OnApplicationShutdown {
18
+ private readonly options;
19
+ private readonly registry;
20
+ private readonly channels?;
21
+ private readonly logger;
22
+ private readonly queues;
23
+ private readonly workers;
24
+ /** Queues whose lease this instance holds. */
25
+ private readonly owned;
26
+ private readonly lastActivity;
27
+ private timer?;
28
+ private ticking?;
29
+ readonly serverId: string;
30
+ constructor(options: DynamicQueuesModuleOptions, registry: DynamicQueuesRegistry, channels?: ChannelsPublisher);
31
+ private get policy();
32
+ private get leaseTtlMs();
33
+ private get state();
34
+ onApplicationBootstrap(): Promise<void>;
35
+ onApplicationShutdown(): Promise<void>;
36
+ /** Producer handle (lazy, cached). Doesn't start a worker or mark the queue active. */
37
+ queue<T extends DynamicQueueType<M>>(type: T, id: string): TypedDynamicQueue<M[T] & object>;
38
+ /** Local worker of the queue, if this instance runs one. */
39
+ worker<T extends DynamicQueueType<M>>(type: T, id: string): Worker<any, any, string>;
40
+ /**
41
+ * Starts the queue here: local worker (resumed if paused), lease owned by this instance,
42
+ * `started` on the channel. Throws when no `@DynamicQueueProcessor` handles the type or
43
+ * `maxLocalWorkers` is reached.
44
+ */
45
+ start<T extends DynamicQueueType<M>>(type: T, id: string): Promise<DynamicQueueHandle<M[T] & object>>;
46
+ /** Pauses the local worker, drops the lease, `paused` on the channel. */
47
+ pause<T extends DynamicQueueType<M>>(type: T, id: string): Promise<void>;
48
+ /**
49
+ * Closes the local worker and queue handle, drops the lease, `removed` on the channel.
50
+ * `obliterate` also deletes the queue's jobs from Redis.
51
+ */
52
+ stop<T extends DynamicQueueType<M>>(type: T, id: string, options?: StopDynamicQueueOptions): Promise<void>;
53
+ isActive<T extends DynamicQueueType<M>>(type: T, id: string): Promise<boolean>;
54
+ /** Active queues of the cluster (names that aren't dynamic queue names are skipped). */
55
+ active(): Promise<DynamicQueueRef[]>;
56
+ /** Local workers for every active queue whose type has a processor here (no ownership). */
57
+ restore(): Promise<void>;
58
+ /**
59
+ * One maintenance round (runs every `heartbeatMs`): renew own leases, give up the ones another
60
+ * instance took, take over stale ones, stop idle queues. Rounds never overlap.
61
+ */
62
+ tick(): Promise<void>;
63
+ /** Every active queue of the cluster with its lease and this instance's view of it. */
64
+ snapshot({ counts }?: {
65
+ counts?: boolean;
66
+ }): Promise<DynamicQueueSnapshot[]>;
67
+ /** Active queues nobody runs: a stale lease, or (with counts) no worker connected anywhere. */
68
+ health(): Promise<DynamicQueuesHealth>;
69
+ /** A change another instance announced on the channel. */
70
+ applyRemote(event: DynamicQueueEvent, name: string): Promise<void>;
71
+ private runTick;
72
+ private stopRef;
73
+ private refOf;
74
+ private atWorkerLimit;
75
+ private touch;
76
+ private queueByName;
77
+ private ensureWorker;
78
+ private process;
79
+ private contextOf;
80
+ private onExhausted;
81
+ private hook;
82
+ private closeWorker;
83
+ private closeLocal;
84
+ private notify;
85
+ }