@holo-js/queue 0.1.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/dist/index.d.ts +560 -0
- package/dist/index.mjs +1638 -0
- package/package.json +34 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { Job, ConnectionOptions } from 'bullmq';
|
|
2
|
+
|
|
3
|
+
type QueueJsonPrimitive = string | number | boolean | null;
|
|
4
|
+
type QueueJsonValue = QueueJsonPrimitive | readonly QueueJsonValue[] | {
|
|
5
|
+
readonly [key: string]: QueueJsonValue;
|
|
6
|
+
};
|
|
7
|
+
declare function normalizeOptionalString(value: string | undefined, label: string): string | undefined;
|
|
8
|
+
declare function normalizeOptionalInteger(value: number | undefined, label: string, options?: {
|
|
9
|
+
minimum?: number;
|
|
10
|
+
}): number | undefined;
|
|
11
|
+
declare function normalizeBackoff(value: number | readonly number[] | undefined): number | readonly number[] | undefined;
|
|
12
|
+
declare function normalizeOptionalHook<THandler extends (...args: never[]) => unknown>(value: THandler | undefined, label: string): THandler | undefined;
|
|
13
|
+
interface QueueJobContext {
|
|
14
|
+
readonly jobId: string;
|
|
15
|
+
readonly jobName: string;
|
|
16
|
+
readonly connection: string;
|
|
17
|
+
readonly queue: string;
|
|
18
|
+
readonly attempt: number;
|
|
19
|
+
readonly maxAttempts: number;
|
|
20
|
+
release(delaySeconds?: number): Promise<void>;
|
|
21
|
+
fail(error: Error): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface QueueJobCompletedHook<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown> {
|
|
24
|
+
(payload: TPayload, result: TResult, context: QueueJobContext): void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
interface QueueJobFailedHook<TPayload extends QueueJsonValue = QueueJsonValue> {
|
|
27
|
+
(payload: TPayload, error: Error, context: QueueJobContext): void | Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
interface QueueJobDefinition<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown> {
|
|
30
|
+
readonly connection?: string;
|
|
31
|
+
readonly queue?: string;
|
|
32
|
+
readonly tries?: number;
|
|
33
|
+
readonly backoff?: number | readonly number[];
|
|
34
|
+
readonly timeout?: number;
|
|
35
|
+
readonly onCompleted?: QueueJobCompletedHook<TPayload, TResult>;
|
|
36
|
+
readonly onFailed?: QueueJobFailedHook<TPayload>;
|
|
37
|
+
handle(payload: TPayload, context: QueueJobContext): Promise<TResult> | TResult;
|
|
38
|
+
}
|
|
39
|
+
interface QueueJobEnvelope<TPayload extends QueueJsonValue = QueueJsonValue> {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly connection: string;
|
|
43
|
+
readonly queue: string;
|
|
44
|
+
readonly payload: TPayload;
|
|
45
|
+
readonly attempts: number;
|
|
46
|
+
readonly maxAttempts: number;
|
|
47
|
+
readonly availableAt?: number;
|
|
48
|
+
readonly createdAt: number;
|
|
49
|
+
}
|
|
50
|
+
type QueueDelayValue = number | Date;
|
|
51
|
+
interface QueueDispatchOptions {
|
|
52
|
+
readonly connection?: string;
|
|
53
|
+
readonly queue?: string;
|
|
54
|
+
readonly delay?: QueueDelayValue;
|
|
55
|
+
}
|
|
56
|
+
interface QueueDispatchResult {
|
|
57
|
+
readonly jobId: string;
|
|
58
|
+
readonly connection: string;
|
|
59
|
+
readonly queue: string;
|
|
60
|
+
readonly synchronous: boolean;
|
|
61
|
+
}
|
|
62
|
+
interface QueueDispatchCompletedHook {
|
|
63
|
+
(result: QueueDispatchResult): void | Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
interface QueueDispatchFailedHook {
|
|
66
|
+
(error: unknown): void | Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
interface QueueDriverDispatchResult<TResult = unknown> {
|
|
69
|
+
readonly jobId: string;
|
|
70
|
+
readonly synchronous: boolean;
|
|
71
|
+
readonly result?: TResult;
|
|
72
|
+
}
|
|
73
|
+
interface QueueRegisteredJob<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown> {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly sourcePath?: string;
|
|
76
|
+
readonly definition: QueueJobDefinition<TPayload, TResult>;
|
|
77
|
+
}
|
|
78
|
+
interface HoloQueueJobRegistry {
|
|
79
|
+
}
|
|
80
|
+
type KnownQueueJobName = Extract<keyof HoloQueueJobRegistry, string>;
|
|
81
|
+
type ResolveRegisteredQueueJobDefinition<TJobName extends string> = TJobName extends KnownQueueJobName ? Extract<HoloQueueJobRegistry[TJobName], QueueJobDefinition> extends never ? QueueJobDefinition : Extract<HoloQueueJobRegistry[TJobName], QueueJobDefinition> : QueueJobDefinition;
|
|
82
|
+
type ExportedQueueJobDefinition<TValue> = Extract<TValue, QueueJobDefinition> extends never ? QueueJobDefinition : Extract<TValue, QueueJobDefinition>;
|
|
83
|
+
type QueuePayloadFor<TJobName extends string> = ResolveRegisteredQueueJobDefinition<TJobName> extends QueueJobDefinition<infer TPayload, unknown> ? TPayload : QueueJsonValue;
|
|
84
|
+
type QueueResultFor<TJobName extends string> = ResolveRegisteredQueueJobDefinition<TJobName> extends QueueJobDefinition<QueueJsonValue, infer TResult> ? TResult : unknown;
|
|
85
|
+
interface RegisterQueueJobOptions {
|
|
86
|
+
readonly name?: string;
|
|
87
|
+
readonly sourcePath?: string;
|
|
88
|
+
readonly replaceExisting?: boolean;
|
|
89
|
+
}
|
|
90
|
+
type RegisterableQueueJobDefinition<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown> = QueueJobDefinition<TPayload, TResult>;
|
|
91
|
+
interface QueuePendingDispatch<TPayload extends QueueJsonValue = QueueJsonValue> extends PromiseLike<QueueDispatchResult> {
|
|
92
|
+
onConnection(name: string): QueuePendingDispatch<TPayload>;
|
|
93
|
+
onQueue(name: string): QueuePendingDispatch<TPayload>;
|
|
94
|
+
delay(value: QueueDelayValue): QueuePendingDispatch<TPayload>;
|
|
95
|
+
onComplete(callback: QueueDispatchCompletedHook): QueuePendingDispatch<TPayload>;
|
|
96
|
+
onFailed(callback: QueueDispatchFailedHook): QueuePendingDispatch<TPayload>;
|
|
97
|
+
then<TResult1 = QueueDispatchResult, TResult2 = never>(onfulfilled?: ((value: QueueDispatchResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
98
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<QueueDispatchResult | TResult>;
|
|
99
|
+
finally(onfinally?: (() => void) | null): Promise<QueueDispatchResult>;
|
|
100
|
+
dispatch(): Promise<QueueDispatchResult>;
|
|
101
|
+
}
|
|
102
|
+
interface QueueConnectionFacade {
|
|
103
|
+
readonly name: string;
|
|
104
|
+
dispatch<TJobName extends KnownQueueJobName>(jobName: TJobName, payload: QueuePayloadFor<TJobName>, options?: QueueDispatchOptions): QueuePendingDispatch<QueuePayloadFor<TJobName>>;
|
|
105
|
+
dispatch<TPayload extends QueueJsonValue = QueueJsonValue>(jobName: string, payload: TPayload, options?: QueueDispatchOptions): QueuePendingDispatch<TPayload>;
|
|
106
|
+
dispatchSync<TJobName extends KnownQueueJobName>(jobName: TJobName, payload: QueuePayloadFor<TJobName>): Promise<QueueResultFor<TJobName>>;
|
|
107
|
+
dispatchSync<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown>(jobName: string, payload: TPayload): Promise<TResult>;
|
|
108
|
+
}
|
|
109
|
+
interface QueueEnqueueResult {
|
|
110
|
+
readonly jobId: string;
|
|
111
|
+
}
|
|
112
|
+
interface QueueReserveInput {
|
|
113
|
+
readonly queueNames: readonly string[];
|
|
114
|
+
readonly workerId: string;
|
|
115
|
+
}
|
|
116
|
+
interface QueueReservedJob<TPayload extends QueueJsonValue = QueueJsonValue> {
|
|
117
|
+
readonly reservationId: string;
|
|
118
|
+
readonly envelope: QueueJobEnvelope<TPayload>;
|
|
119
|
+
readonly reservedAt: number;
|
|
120
|
+
}
|
|
121
|
+
interface QueueReleaseOptions {
|
|
122
|
+
readonly delaySeconds?: number;
|
|
123
|
+
}
|
|
124
|
+
interface QueueClearInput {
|
|
125
|
+
readonly queueNames?: readonly string[];
|
|
126
|
+
}
|
|
127
|
+
interface QueueJobContextOverrides {
|
|
128
|
+
readonly maxAttempts?: number;
|
|
129
|
+
shouldSkipLifecycleHooks?(): boolean;
|
|
130
|
+
release?(delaySeconds?: number): Promise<void>;
|
|
131
|
+
fail?(error: Error): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
interface QueueDriverFactoryContext {
|
|
134
|
+
execute<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown>(job: QueueJobEnvelope<TPayload>): Promise<TResult>;
|
|
135
|
+
}
|
|
136
|
+
interface QueueDriverBase {
|
|
137
|
+
readonly name: string;
|
|
138
|
+
readonly driver: NormalizedQueueConnectionConfig['driver'];
|
|
139
|
+
readonly mode: 'sync' | 'async';
|
|
140
|
+
dispatch<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown>(job: QueueJobEnvelope<TPayload>): Promise<QueueDriverDispatchResult<TResult>>;
|
|
141
|
+
clear(input?: QueueClearInput): Promise<number>;
|
|
142
|
+
close(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
interface QueueAsyncDriver extends QueueDriverBase {
|
|
145
|
+
readonly mode: 'async';
|
|
146
|
+
reserve<TPayload extends QueueJsonValue = QueueJsonValue>(input: QueueReserveInput): Promise<QueueReservedJob<TPayload> | null>;
|
|
147
|
+
acknowledge(job: QueueReservedJob): Promise<void>;
|
|
148
|
+
release(job: QueueReservedJob, options?: QueueReleaseOptions): Promise<void>;
|
|
149
|
+
delete(job: QueueReservedJob): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
interface QueueSyncDriver extends QueueDriverBase {
|
|
152
|
+
readonly mode: 'sync';
|
|
153
|
+
}
|
|
154
|
+
type QueueDriver = QueueSyncDriver | QueueAsyncDriver;
|
|
155
|
+
interface QueueDriverFactory<TConfig extends NormalizedQueueConnectionConfig = NormalizedQueueConnectionConfig> {
|
|
156
|
+
readonly driver: TConfig['driver'];
|
|
157
|
+
create(connection: TConfig, context: QueueDriverFactoryContext): QueueDriver;
|
|
158
|
+
}
|
|
159
|
+
interface QueueRuntimeBinding {
|
|
160
|
+
readonly config: NormalizedHoloQueueConfig;
|
|
161
|
+
readonly drivers: ReadonlyMap<string, QueueDriver>;
|
|
162
|
+
}
|
|
163
|
+
interface QueueWorkerOptions {
|
|
164
|
+
readonly connection?: string;
|
|
165
|
+
readonly queueNames?: readonly string[];
|
|
166
|
+
readonly once?: boolean;
|
|
167
|
+
readonly stopWhenEmpty?: boolean;
|
|
168
|
+
readonly sleep?: number;
|
|
169
|
+
readonly tries?: number;
|
|
170
|
+
readonly timeout?: number;
|
|
171
|
+
readonly maxJobs?: number;
|
|
172
|
+
readonly maxTime?: number;
|
|
173
|
+
readonly workerId?: string;
|
|
174
|
+
readonly shouldStop?: () => boolean | Promise<boolean>;
|
|
175
|
+
readonly sleepFn?: (milliseconds: number) => Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
interface QueueWorkerJobEvent {
|
|
178
|
+
readonly jobId: string;
|
|
179
|
+
readonly jobName: string;
|
|
180
|
+
readonly connection: string;
|
|
181
|
+
readonly queue: string;
|
|
182
|
+
readonly attempt: number;
|
|
183
|
+
readonly maxAttempts: number;
|
|
184
|
+
}
|
|
185
|
+
interface QueueWorkerHooks {
|
|
186
|
+
onJobProcessed?(event: QueueWorkerJobEvent): void | Promise<void>;
|
|
187
|
+
onJobReleased?(event: QueueWorkerJobEvent & {
|
|
188
|
+
readonly delaySeconds?: number;
|
|
189
|
+
readonly error?: Error;
|
|
190
|
+
}): void | Promise<void>;
|
|
191
|
+
onJobFailed?(event: QueueWorkerJobEvent & {
|
|
192
|
+
readonly error: Error;
|
|
193
|
+
}): void | Promise<void>;
|
|
194
|
+
onIdle?(): void | Promise<void>;
|
|
195
|
+
}
|
|
196
|
+
interface QueueWorkerRunOptions extends QueueWorkerOptions, QueueWorkerHooks {
|
|
197
|
+
}
|
|
198
|
+
interface QueueWorkerResult {
|
|
199
|
+
readonly processed: number;
|
|
200
|
+
readonly released: number;
|
|
201
|
+
readonly failed: number;
|
|
202
|
+
readonly stoppedBecause: 'once' | 'empty' | 'max-jobs' | 'max-time' | 'signal';
|
|
203
|
+
}
|
|
204
|
+
interface QueueFailedJobRecord<TPayload extends QueueJsonValue = QueueJsonValue> {
|
|
205
|
+
readonly id: string;
|
|
206
|
+
readonly jobId: string;
|
|
207
|
+
readonly job: QueueJobEnvelope<TPayload>;
|
|
208
|
+
readonly exception: string;
|
|
209
|
+
readonly failedAt: number;
|
|
210
|
+
}
|
|
211
|
+
interface QueueFailedJobStore {
|
|
212
|
+
persistFailedJob(reserved: QueueReservedJob, error: Error): Promise<QueueFailedJobRecord | null>;
|
|
213
|
+
listFailedJobs(): Promise<readonly QueueFailedJobRecord[]>;
|
|
214
|
+
retryFailedJobs(identifier: 'all' | string, retry: (record: QueueFailedJobRecord) => Promise<void>): Promise<number>;
|
|
215
|
+
forgetFailedJob(id: string): Promise<boolean>;
|
|
216
|
+
flushFailedJobs(): Promise<number>;
|
|
217
|
+
}
|
|
218
|
+
declare function isQueueJobDefinition(value: unknown): value is QueueJobDefinition;
|
|
219
|
+
declare function normalizeQueueJobDefinition<TJob extends QueueJobDefinition>(job: TJob): TJob;
|
|
220
|
+
declare function defineJob<TJob extends QueueJobDefinition>(job: TJob): TJob;
|
|
221
|
+
interface QueueFailedStoreConfig {
|
|
222
|
+
readonly driver?: 'database';
|
|
223
|
+
readonly connection?: string;
|
|
224
|
+
readonly table?: string;
|
|
225
|
+
}
|
|
226
|
+
interface QueueRedisConnectionConfig {
|
|
227
|
+
readonly driver: 'redis';
|
|
228
|
+
readonly queue?: string;
|
|
229
|
+
readonly retryAfter?: number | string;
|
|
230
|
+
readonly blockFor?: number | string;
|
|
231
|
+
readonly redis?: {
|
|
232
|
+
readonly host?: string;
|
|
233
|
+
readonly port?: number | string;
|
|
234
|
+
readonly password?: string;
|
|
235
|
+
readonly username?: string;
|
|
236
|
+
readonly db?: number | string;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
interface QueueDatabaseConnectionConfig {
|
|
240
|
+
readonly driver: 'database';
|
|
241
|
+
readonly queue?: string;
|
|
242
|
+
readonly retryAfter?: number | string;
|
|
243
|
+
readonly sleep?: number | string;
|
|
244
|
+
readonly connection?: string;
|
|
245
|
+
readonly table?: string;
|
|
246
|
+
}
|
|
247
|
+
interface QueueSyncConnectionConfig {
|
|
248
|
+
readonly driver: 'sync';
|
|
249
|
+
readonly queue?: string;
|
|
250
|
+
}
|
|
251
|
+
type QueueConnectionConfig = QueueSyncConnectionConfig | QueueRedisConnectionConfig | QueueDatabaseConnectionConfig;
|
|
252
|
+
interface HoloQueueConfig {
|
|
253
|
+
readonly default?: string;
|
|
254
|
+
readonly failed?: false | QueueFailedStoreConfig;
|
|
255
|
+
readonly connections?: Readonly<Record<string, QueueConnectionConfig>>;
|
|
256
|
+
}
|
|
257
|
+
interface NormalizedQueueFailedStoreConfig {
|
|
258
|
+
readonly driver: 'database';
|
|
259
|
+
readonly connection: string;
|
|
260
|
+
readonly table: string;
|
|
261
|
+
}
|
|
262
|
+
interface NormalizedQueueSyncConnectionConfig {
|
|
263
|
+
readonly name: string;
|
|
264
|
+
readonly driver: 'sync';
|
|
265
|
+
readonly queue: string;
|
|
266
|
+
}
|
|
267
|
+
interface NormalizedQueueRedisConnectionConfig {
|
|
268
|
+
readonly name: string;
|
|
269
|
+
readonly driver: 'redis';
|
|
270
|
+
readonly queue: string;
|
|
271
|
+
readonly retryAfter: number;
|
|
272
|
+
readonly blockFor: number;
|
|
273
|
+
readonly redis: {
|
|
274
|
+
readonly host: string;
|
|
275
|
+
readonly port: number;
|
|
276
|
+
readonly password?: string;
|
|
277
|
+
readonly username?: string;
|
|
278
|
+
readonly db: number;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
interface NormalizedQueueDatabaseConnectionConfig {
|
|
282
|
+
readonly name: string;
|
|
283
|
+
readonly driver: 'database';
|
|
284
|
+
readonly queue: string;
|
|
285
|
+
readonly retryAfter: number;
|
|
286
|
+
readonly sleep: number;
|
|
287
|
+
readonly connection: string;
|
|
288
|
+
readonly table: string;
|
|
289
|
+
}
|
|
290
|
+
type NormalizedQueueConnectionConfig = NormalizedQueueSyncConnectionConfig | NormalizedQueueRedisConnectionConfig | NormalizedQueueDatabaseConnectionConfig;
|
|
291
|
+
interface NormalizedHoloQueueConfig {
|
|
292
|
+
readonly default: string;
|
|
293
|
+
readonly failed: false | NormalizedQueueFailedStoreConfig;
|
|
294
|
+
readonly connections: Readonly<Record<string, NormalizedQueueConnectionConfig>>;
|
|
295
|
+
}
|
|
296
|
+
declare const queueJobInternals: {
|
|
297
|
+
normalizeQueueJobDefinition: typeof normalizeQueueJobDefinition;
|
|
298
|
+
normalizeBackoff: typeof normalizeBackoff;
|
|
299
|
+
normalizeOptionalHook: typeof normalizeOptionalHook;
|
|
300
|
+
normalizeOptionalInteger: typeof normalizeOptionalInteger;
|
|
301
|
+
normalizeOptionalString: typeof normalizeOptionalString;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
declare const DEFAULT_QUEUE_CONNECTION = "sync";
|
|
305
|
+
declare const DEFAULT_QUEUE_NAME = "default";
|
|
306
|
+
declare const DEFAULT_QUEUE_RETRY_AFTER = 90;
|
|
307
|
+
declare const DEFAULT_QUEUE_BLOCK_FOR = 5;
|
|
308
|
+
declare const DEFAULT_QUEUE_SLEEP = 1;
|
|
309
|
+
declare const DEFAULT_FAILED_JOBS_CONNECTION = "default";
|
|
310
|
+
declare const DEFAULT_FAILED_JOBS_TABLE = "failed_jobs";
|
|
311
|
+
declare const DEFAULT_DATABASE_QUEUE_TABLE = "jobs";
|
|
312
|
+
declare function parseInteger(value: number | string | undefined, fallback: number, label: string, options?: {
|
|
313
|
+
minimum?: number;
|
|
314
|
+
}): number;
|
|
315
|
+
declare function normalizeQueueConfig(config?: HoloQueueConfig): NormalizedHoloQueueConfig;
|
|
316
|
+
declare const holoQueueDefaults: Readonly<NormalizedHoloQueueConfig>;
|
|
317
|
+
declare const queueInternals: {
|
|
318
|
+
parseInteger: typeof parseInteger;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
declare function deriveJobNameFromSourcePath(sourcePath: string): string;
|
|
322
|
+
declare function registerQueueJob<TPayload extends QueueJsonValue, TResult>(definition: RegisterableQueueJobDefinition<TPayload, TResult>, options?: RegisterQueueJobOptions): QueueRegisteredJob<TPayload, TResult>;
|
|
323
|
+
declare function registerQueueJobs(definitions: ReadonlyArray<{
|
|
324
|
+
readonly definition: RegisterableQueueJobDefinition;
|
|
325
|
+
readonly options?: RegisterQueueJobOptions;
|
|
326
|
+
}>): ReadonlyArray<QueueRegisteredJob>;
|
|
327
|
+
declare function getRegisteredQueueJob(name: string): QueueRegisteredJob | undefined;
|
|
328
|
+
declare function listRegisteredQueueJobs(): readonly QueueRegisteredJob[];
|
|
329
|
+
declare function unregisterQueueJob(name: string): boolean;
|
|
330
|
+
declare function resetQueueRegistry(): void;
|
|
331
|
+
declare const queueRegistryInternals: {
|
|
332
|
+
deriveJobNameFromSourcePath: typeof deriveJobNameFromSourcePath;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
type RedisQueuedEnvelope = QueueJobEnvelope<QueueJsonValue>;
|
|
336
|
+
type BullJobInstance = Job<RedisQueuedEnvelope, unknown, string>;
|
|
337
|
+
declare function normalizeRedisErrorMessage(error: unknown): string;
|
|
338
|
+
declare function isQueueEnvelope(value: unknown): value is QueueJobEnvelope<QueueJsonValue>;
|
|
339
|
+
declare function resolveBullConnectionOptions(connection: NormalizedQueueRedisConnectionConfig): ConnectionOptions;
|
|
340
|
+
declare class RedisQueueDriverError extends Error {
|
|
341
|
+
constructor(connectionName: string, action: string, cause: unknown);
|
|
342
|
+
}
|
|
343
|
+
declare function wrapRedisError(connectionName: string, action: string, error: unknown): RedisQueueDriverError;
|
|
344
|
+
declare function resolveAttempts(job: BullJobInstance): number;
|
|
345
|
+
declare class RedisQueueDriver implements QueueAsyncDriver {
|
|
346
|
+
private readonly context;
|
|
347
|
+
readonly name: string;
|
|
348
|
+
readonly driver: "redis";
|
|
349
|
+
readonly mode: "async";
|
|
350
|
+
private readonly connection;
|
|
351
|
+
private readonly bullConnection;
|
|
352
|
+
private readonly queues;
|
|
353
|
+
private readonly workers;
|
|
354
|
+
private readonly reservations;
|
|
355
|
+
private queueCursor;
|
|
356
|
+
constructor(connection: NormalizedQueueRedisConnectionConfig, context: QueueDriverFactoryContext);
|
|
357
|
+
private getQueue;
|
|
358
|
+
private getWorker;
|
|
359
|
+
private normalizeQueueNames;
|
|
360
|
+
private rotateQueueNames;
|
|
361
|
+
private createReservedJob;
|
|
362
|
+
private getReservation;
|
|
363
|
+
private settleReservation;
|
|
364
|
+
dispatch<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown>(job: QueueJobEnvelope<TPayload>): Promise<QueueDriverDispatchResult<TResult>>;
|
|
365
|
+
reserve<TPayload extends QueueJsonValue = QueueJsonValue>(input: {
|
|
366
|
+
readonly queueNames: readonly string[];
|
|
367
|
+
readonly workerId: string;
|
|
368
|
+
}): Promise<QueueReservedJob<TPayload> | null>;
|
|
369
|
+
acknowledge(job: QueueReservedJob): Promise<void>;
|
|
370
|
+
release(job: QueueReservedJob, options?: QueueReleaseOptions): Promise<void>;
|
|
371
|
+
delete(job: QueueReservedJob): Promise<void>;
|
|
372
|
+
clear(input?: {
|
|
373
|
+
readonly queueNames?: readonly string[];
|
|
374
|
+
}): Promise<number>;
|
|
375
|
+
close(): Promise<void>;
|
|
376
|
+
}
|
|
377
|
+
declare const redisQueueDriverFactory: QueueDriverFactory<NormalizedQueueRedisConnectionConfig>;
|
|
378
|
+
declare const redisQueueDriverInternals: {
|
|
379
|
+
isQueueEnvelope: typeof isQueueEnvelope;
|
|
380
|
+
normalizeRedisErrorMessage: typeof normalizeRedisErrorMessage;
|
|
381
|
+
resolveAttempts: typeof resolveAttempts;
|
|
382
|
+
resolveBullConnectionOptions: typeof resolveBullConnectionOptions;
|
|
383
|
+
wrapRedisError: typeof wrapRedisError;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
declare class SyncQueueDriver implements QueueSyncDriver {
|
|
387
|
+
readonly name: string;
|
|
388
|
+
readonly driver: "sync";
|
|
389
|
+
readonly mode: "sync";
|
|
390
|
+
private readonly context;
|
|
391
|
+
constructor(connection: NormalizedQueueSyncConnectionConfig, context: QueueDriverFactoryContext);
|
|
392
|
+
dispatch<TPayload extends QueueJsonValue = QueueJsonValue, TResult = unknown>(job: QueueJobEnvelope<TPayload>): Promise<QueueDriverDispatchResult<TResult>>;
|
|
393
|
+
clear(): Promise<number>;
|
|
394
|
+
close(): Promise<void>;
|
|
395
|
+
}
|
|
396
|
+
declare const syncQueueDriverFactory: QueueDriverFactory<NormalizedQueueSyncConnectionConfig>;
|
|
397
|
+
declare const syncQueueDriverInternals: {
|
|
398
|
+
SyncQueueDriver: typeof SyncQueueDriver;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
type RuntimeQueueState = {
|
|
402
|
+
config: NormalizedHoloQueueConfig;
|
|
403
|
+
driverFactories: Map<string, QueueDriverFactory>;
|
|
404
|
+
drivers: Map<string, QueueDriver>;
|
|
405
|
+
failedJobStore?: QueueFailedJobStore;
|
|
406
|
+
};
|
|
407
|
+
type QueuePayloadValidationState = {
|
|
408
|
+
readonly seen: Set<unknown>;
|
|
409
|
+
};
|
|
410
|
+
type ConfigureQueueRuntimeOptions = {
|
|
411
|
+
readonly config?: HoloQueueConfig | NormalizedHoloQueueConfig;
|
|
412
|
+
readonly driverFactories?: ReadonlyArray<QueueDriverFactory> | ReadonlyMap<string, QueueDriverFactory>;
|
|
413
|
+
readonly failedJobStore?: QueueFailedJobStore;
|
|
414
|
+
};
|
|
415
|
+
declare class QueueReleaseUnsupportedError extends Error {
|
|
416
|
+
constructor();
|
|
417
|
+
}
|
|
418
|
+
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
419
|
+
declare function assertQueueJsonValue(value: unknown, path: string, state: QueuePayloadValidationState): asserts value is QueueJsonValue;
|
|
420
|
+
declare function validateQueuePayload<TPayload>(payload: TPayload): asserts payload is TPayload & QueueJsonValue;
|
|
421
|
+
declare function normalizeConnectionName(name: string): string;
|
|
422
|
+
declare function normalizeQueueName(name: string): string;
|
|
423
|
+
declare function normalizeDelay(delay: QueueDelayValue | undefined): number | undefined;
|
|
424
|
+
declare function createDefaultDriverFactories(): Map<string, QueueDriverFactory>;
|
|
425
|
+
declare function createQueueDriverFactoryMap(factories?: ReadonlyArray<QueueDriverFactory> | ReadonlyMap<string, QueueDriverFactory>): Map<string, QueueDriverFactory>;
|
|
426
|
+
declare function getQueueRuntimeState(): RuntimeQueueState;
|
|
427
|
+
declare function createQueueRuntimeBinding(state: RuntimeQueueState): QueueRuntimeBinding;
|
|
428
|
+
declare function resolveConnectionConfig(config: NormalizedHoloQueueConfig, requestedConnection: string | undefined): NormalizedQueueConnectionConfig;
|
|
429
|
+
declare function createJobContext<TPayload extends QueueJsonValue>(envelope: QueueJobEnvelope<TPayload>, overrides?: QueueJobContextOverrides): QueueJobContext;
|
|
430
|
+
declare function executeRegisteredQueueJob<TPayload extends QueueJsonValue, TResult>(envelope: QueueJobEnvelope<TPayload>, contextOverrides?: QueueJobContextOverrides): Promise<TResult>;
|
|
431
|
+
declare function executeRegisteredQueueJobCompletedHook<TPayload extends QueueJsonValue, TResult>(envelope: QueueJobEnvelope<TPayload>, result: TResult, contextOverrides?: QueueJobContextOverrides): Promise<void>;
|
|
432
|
+
declare function executeRegisteredQueueJobFailedHook<TPayload extends QueueJsonValue>(envelope: QueueJobEnvelope<TPayload>, error: Error, contextOverrides?: QueueJobContextOverrides): Promise<void>;
|
|
433
|
+
declare function dispatchThroughDriver(driver: QueueDriver, envelope: QueueJobEnvelope): Promise<Awaited<ReturnType<QueueDriver['dispatch']>>>;
|
|
434
|
+
declare function createQueueDriverFactoryContext(): QueueDriverFactoryContext;
|
|
435
|
+
declare function resolveDriverFactory(state: RuntimeQueueState, connection: NormalizedQueueConnectionConfig): QueueDriverFactory;
|
|
436
|
+
declare function resolveConnectionDriver(connectionName?: string): QueueDriver;
|
|
437
|
+
declare function resolveSyncExecutionDriver(): QueueDriver;
|
|
438
|
+
declare function createJobEnvelope<TPayload extends QueueJsonValue>(jobName: string, payload: TPayload, options: QueueDispatchOptions): QueueJobEnvelope<TPayload>;
|
|
439
|
+
declare function createDispatchEnvelope<TPayload extends QueueJsonValue>(jobName: string, payload: TPayload, options?: QueueDispatchOptions): QueueJobEnvelope<TPayload>;
|
|
440
|
+
declare function dispatchRecord(envelope: QueueJobEnvelope): Promise<QueueDispatchResult>;
|
|
441
|
+
declare function createQueueConnection(name?: string): QueueConnectionFacade;
|
|
442
|
+
declare function configureQueueRuntime(options?: ConfigureQueueRuntimeOptions): void;
|
|
443
|
+
declare function resetQueueRuntimeState(state: RuntimeQueueState): void;
|
|
444
|
+
declare function shutdownQueueRuntime(): Promise<void>;
|
|
445
|
+
declare function resetQueueRuntime(): void;
|
|
446
|
+
declare function getQueueRuntime(): QueueRuntimeBinding;
|
|
447
|
+
declare function useQueueConnection(name?: string): QueueConnectionFacade;
|
|
448
|
+
declare function dispatchSync<TJobName extends Extract<keyof HoloQueueJobRegistry, string>>(jobName: TJobName, payload: QueuePayloadFor<TJobName>, options?: QueueDispatchOptions): Promise<QueueResultFor<TJobName>>;
|
|
449
|
+
declare function dispatch<TJobName extends Extract<keyof HoloQueueJobRegistry, string>>(jobName: TJobName, payload: QueuePayloadFor<TJobName>, options?: QueueDispatchOptions): QueuePendingDispatch<QueuePayloadFor<TJobName>>;
|
|
450
|
+
declare const Queue: {
|
|
451
|
+
connection(name?: string): QueueConnectionFacade;
|
|
452
|
+
dispatch: typeof dispatch;
|
|
453
|
+
dispatchSync: typeof dispatchSync;
|
|
454
|
+
};
|
|
455
|
+
declare const queueRuntimeInternals: {
|
|
456
|
+
assertQueueJsonValue: typeof assertQueueJsonValue;
|
|
457
|
+
createQueueRuntimeBinding: typeof createQueueRuntimeBinding;
|
|
458
|
+
createDefaultDriverFactories: typeof createDefaultDriverFactories;
|
|
459
|
+
createDispatchEnvelope: typeof createDispatchEnvelope;
|
|
460
|
+
createJobContext: typeof createJobContext;
|
|
461
|
+
createJobEnvelope: typeof createJobEnvelope;
|
|
462
|
+
createQueueConnection: typeof createQueueConnection;
|
|
463
|
+
createQueueDriverFactoryContext: typeof createQueueDriverFactoryContext;
|
|
464
|
+
createQueueDriverFactoryMap: typeof createQueueDriverFactoryMap;
|
|
465
|
+
closeQueueDrivers: typeof closeQueueDrivers;
|
|
466
|
+
dispatchRecord: typeof dispatchRecord;
|
|
467
|
+
dispatchThroughDriver: typeof dispatchThroughDriver;
|
|
468
|
+
executeRegisteredQueueJob: typeof executeRegisteredQueueJob;
|
|
469
|
+
executeRegisteredQueueJobCompletedHook: typeof executeRegisteredQueueJobCompletedHook;
|
|
470
|
+
executeRegisteredQueueJobFailedHook: typeof executeRegisteredQueueJobFailedHook;
|
|
471
|
+
getQueueRuntimeState: typeof getQueueRuntimeState;
|
|
472
|
+
isPlainObject: typeof isPlainObject;
|
|
473
|
+
normalizeConnectionName: typeof normalizeConnectionName;
|
|
474
|
+
normalizeDelay: typeof normalizeDelay;
|
|
475
|
+
normalizeQueueName: typeof normalizeQueueName;
|
|
476
|
+
resolveConnectionConfig: typeof resolveConnectionConfig;
|
|
477
|
+
resolveConnectionDriver: typeof resolveConnectionDriver;
|
|
478
|
+
resolveDriverFactory: typeof resolveDriverFactory;
|
|
479
|
+
resolveSyncExecutionDriver: typeof resolveSyncExecutionDriver;
|
|
480
|
+
resetQueueRuntimeState: typeof resetQueueRuntimeState;
|
|
481
|
+
validateQueuePayload: typeof validateQueuePayload;
|
|
482
|
+
};
|
|
483
|
+
declare function closeQueueDrivers(drivers: Iterable<QueueDriver>): Promise<void>;
|
|
484
|
+
|
|
485
|
+
declare function normalizeFailedStoreErrorMessage(error: unknown): string;
|
|
486
|
+
declare class QueueFailedStoreError extends Error {
|
|
487
|
+
constructor(action: string, cause: unknown);
|
|
488
|
+
}
|
|
489
|
+
declare function wrapFailedStoreError(action: string, error: unknown): QueueFailedStoreError;
|
|
490
|
+
declare function getFailedJobStore(): QueueFailedJobStore | undefined;
|
|
491
|
+
declare function createRetriedEnvelope(record: QueueFailedJobRecord): Readonly<{
|
|
492
|
+
attempts: 0;
|
|
493
|
+
createdAt: number;
|
|
494
|
+
availableAt: undefined;
|
|
495
|
+
id: string;
|
|
496
|
+
name: string;
|
|
497
|
+
connection: string;
|
|
498
|
+
queue: string;
|
|
499
|
+
payload: QueueJsonValue;
|
|
500
|
+
maxAttempts: number;
|
|
501
|
+
}>;
|
|
502
|
+
declare function persistFailedQueueJob(reserved: QueueReservedJob, error: Error): Promise<QueueFailedJobRecord | null>;
|
|
503
|
+
declare function listFailedQueueJobs(): Promise<readonly QueueFailedJobRecord[]>;
|
|
504
|
+
declare function retryFailedQueueJobs(identifier: 'all' | string): Promise<number>;
|
|
505
|
+
declare function forgetFailedQueueJob(id: string): Promise<boolean>;
|
|
506
|
+
declare function flushFailedQueueJobs(): Promise<number>;
|
|
507
|
+
declare const queueFailedInternals: {
|
|
508
|
+
createRetriedEnvelope: typeof createRetriedEnvelope;
|
|
509
|
+
getFailedJobStore: typeof getFailedJobStore;
|
|
510
|
+
normalizeFailedStoreErrorMessage: typeof normalizeFailedStoreErrorMessage;
|
|
511
|
+
wrapFailedStoreError: typeof wrapFailedStoreError;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
declare class QueueWorkerUnsupportedDriverError extends Error {
|
|
515
|
+
constructor(connectionName: string, driverName: string);
|
|
516
|
+
}
|
|
517
|
+
declare class QueueWorkerTimeoutError extends Error {
|
|
518
|
+
constructor(jobName: string, timeoutSeconds: number);
|
|
519
|
+
}
|
|
520
|
+
type QueueWorkerProcessingOutcome = {
|
|
521
|
+
readonly kind: 'processed';
|
|
522
|
+
} | {
|
|
523
|
+
readonly kind: 'released';
|
|
524
|
+
readonly delaySeconds?: number;
|
|
525
|
+
readonly error?: Error;
|
|
526
|
+
} | {
|
|
527
|
+
readonly kind: 'failed';
|
|
528
|
+
readonly error: Error;
|
|
529
|
+
};
|
|
530
|
+
declare function sleep(milliseconds: number): Promise<void>;
|
|
531
|
+
declare function requireAsyncDriver(driver: QueueDriver, connectionName: string): QueueAsyncDriver;
|
|
532
|
+
declare function requireRegisteredDefinition(jobName: string): QueueJobDefinition;
|
|
533
|
+
declare function normalizeQueueNames(queueNames: readonly string[] | undefined, fallbackQueueName: string | undefined): readonly string[];
|
|
534
|
+
declare function normalizeNonNegativeInteger(value: number | undefined, label: string): number | undefined;
|
|
535
|
+
declare function normalizePositiveInteger(value: number | undefined, label: string): number | undefined;
|
|
536
|
+
declare function createWorkerEvent(envelope: QueueJobEnvelope, maxAttempts: number): QueueWorkerJobEvent;
|
|
537
|
+
declare function resolveRetryDelaySeconds(definition: QueueJobDefinition, attempt: number): number | undefined;
|
|
538
|
+
declare function runWithTimeout<TResult>(callback: Promise<TResult>, jobName: string, timeoutSeconds: number | undefined, onTimeout?: () => void): Promise<TResult>;
|
|
539
|
+
declare function processReservedJob(driver: QueueAsyncDriver, reserved: QueueReservedJob<QueueJsonValue>, options: Pick<QueueWorkerRunOptions, 'timeout' | 'tries' | 'onJobFailed' | 'onJobProcessed' | 'onJobReleased'>): Promise<QueueWorkerProcessingOutcome>;
|
|
540
|
+
declare function resolveWorkerStopReason(options: QueueWorkerOptions, state: {
|
|
541
|
+
readonly processed: number;
|
|
542
|
+
readonly startedAt: number;
|
|
543
|
+
}): QueueWorkerResult['stoppedBecause'] | undefined;
|
|
544
|
+
declare function runQueueWorker(options?: QueueWorkerRunOptions): Promise<QueueWorkerResult>;
|
|
545
|
+
declare function clearQueueConnection(connectionName?: string, input?: QueueClearInput): Promise<number>;
|
|
546
|
+
declare const queueWorkerInternals: {
|
|
547
|
+
createWorkerEvent: typeof createWorkerEvent;
|
|
548
|
+
normalizeNonNegativeInteger: typeof normalizeNonNegativeInteger;
|
|
549
|
+
normalizePositiveInteger: typeof normalizePositiveInteger;
|
|
550
|
+
normalizeQueueNames: typeof normalizeQueueNames;
|
|
551
|
+
processReservedJob: typeof processReservedJob;
|
|
552
|
+
requireAsyncDriver: typeof requireAsyncDriver;
|
|
553
|
+
requireRegisteredDefinition: typeof requireRegisteredDefinition;
|
|
554
|
+
resolveRetryDelaySeconds: typeof resolveRetryDelaySeconds;
|
|
555
|
+
resolveWorkerStopReason: typeof resolveWorkerStopReason;
|
|
556
|
+
runWithTimeout: typeof runWithTimeout;
|
|
557
|
+
sleep: typeof sleep;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
export { DEFAULT_DATABASE_QUEUE_TABLE, DEFAULT_FAILED_JOBS_CONNECTION, DEFAULT_FAILED_JOBS_TABLE, DEFAULT_QUEUE_BLOCK_FOR, DEFAULT_QUEUE_CONNECTION, DEFAULT_QUEUE_NAME, DEFAULT_QUEUE_RETRY_AFTER, DEFAULT_QUEUE_SLEEP, type ExportedQueueJobDefinition, type HoloQueueConfig, type HoloQueueJobRegistry, type NormalizedHoloQueueConfig, type NormalizedQueueConnectionConfig, type NormalizedQueueDatabaseConnectionConfig, type NormalizedQueueFailedStoreConfig, type NormalizedQueueRedisConnectionConfig, type NormalizedQueueSyncConnectionConfig, Queue, type QueueAsyncDriver, type QueueClearInput, type QueueConnectionConfig, type QueueConnectionFacade, type QueueDatabaseConnectionConfig, type QueueDelayValue, type QueueDispatchCompletedHook, type QueueDispatchFailedHook, type QueueDispatchOptions, type QueueDispatchResult, type QueueDriver, type QueueDriverDispatchResult, type QueueDriverFactory, type QueueDriverFactoryContext, type QueueEnqueueResult, type QueueFailedJobRecord, type QueueFailedJobStore, type QueueFailedStoreConfig, QueueFailedStoreError, type QueueJobContext, type QueueJobContextOverrides, type QueueJobDefinition, type QueueJobEnvelope, type QueueJsonValue, type QueuePayloadFor, type QueuePendingDispatch, type QueueRedisConnectionConfig, type QueueRegisteredJob, type QueueReleaseOptions, QueueReleaseUnsupportedError, type QueueReserveInput, type QueueReservedJob, type QueueResultFor, type QueueRuntimeBinding, type QueueSyncConnectionConfig, type QueueSyncDriver, type QueueWorkerHooks, type QueueWorkerJobEvent, type QueueWorkerOptions, type QueueWorkerResult, type QueueWorkerRunOptions, QueueWorkerTimeoutError, QueueWorkerUnsupportedDriverError, RedisQueueDriver, RedisQueueDriverError, type RegisterQueueJobOptions, type RegisterableQueueJobDefinition, clearQueueConnection, configureQueueRuntime, defineJob, dispatch, dispatchSync, flushFailedQueueJobs, forgetFailedQueueJob, getQueueRuntime, getRegisteredQueueJob, holoQueueDefaults, isQueueJobDefinition, listFailedQueueJobs, listRegisteredQueueJobs, normalizeQueueConfig, normalizeQueueJobDefinition, persistFailedQueueJob, queueFailedInternals, queueInternals, queueJobInternals, queueRegistryInternals, queueRuntimeInternals, queueWorkerInternals, redisQueueDriverFactory, redisQueueDriverInternals, registerQueueJob, registerQueueJobs, resetQueueRegistry, resetQueueRuntime, retryFailedQueueJobs, runQueueWorker, shutdownQueueRuntime, syncQueueDriverFactory, syncQueueDriverInternals, unregisterQueueJob, useQueueConnection };
|