bullmq 1.91.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cjs/classes/child-processor.js +0 -20
  2. package/dist/cjs/classes/child-processor.js.map +1 -1
  3. package/dist/cjs/classes/index.d.ts +0 -2
  4. package/dist/cjs/classes/index.js +0 -2
  5. package/dist/cjs/classes/index.js.map +1 -1
  6. package/dist/cjs/classes/queue-getters.d.ts +1 -0
  7. package/dist/cjs/classes/queue-getters.js +27 -2
  8. package/dist/cjs/classes/queue-getters.js.map +1 -1
  9. package/dist/cjs/classes/redis-connection.d.ts +2 -1
  10. package/dist/cjs/classes/redis-connection.js +5 -0
  11. package/dist/cjs/classes/redis-connection.js.map +1 -1
  12. package/dist/cjs/classes/scripts.js +6 -4
  13. package/dist/cjs/classes/scripts.js.map +1 -1
  14. package/dist/cjs/classes/worker.d.ts +11 -0
  15. package/dist/cjs/classes/worker.js +54 -21
  16. package/dist/cjs/classes/worker.js.map +1 -1
  17. package/dist/{esm/commands/addJob-9.lua → cjs/commands/addJob-8.lua} +10 -2
  18. package/dist/cjs/commands/includes/checkStalledJobs.lua +136 -0
  19. package/dist/cjs/commands/includes/getNextDelayedTimestamp.lua +13 -0
  20. package/dist/cjs/commands/includes/moveJobFromWaitToActive.lua +1 -4
  21. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +57 -0
  22. package/dist/cjs/commands/moveStalledJobsToWait-8.lua +4 -102
  23. package/dist/cjs/commands/moveToActive-9.lua +67 -0
  24. package/dist/cjs/commands/moveToFinished-12.lua +20 -5
  25. package/dist/cjs/commands/promote-6.lua +6 -0
  26. package/dist/cjs/interfaces/index.d.ts +0 -1
  27. package/dist/cjs/interfaces/index.js +0 -1
  28. package/dist/cjs/interfaces/index.js.map +1 -1
  29. package/dist/cjs/interfaces/sandboxed-job.d.ts +0 -1
  30. package/dist/cjs/interfaces/worker-options.d.ts +10 -0
  31. package/dist/esm/classes/child-processor.js +0 -20
  32. package/dist/esm/classes/child-processor.js.map +1 -1
  33. package/dist/esm/classes/index.d.ts +0 -2
  34. package/dist/esm/classes/index.js +0 -2
  35. package/dist/esm/classes/index.js.map +1 -1
  36. package/dist/esm/classes/queue-getters.d.ts +1 -0
  37. package/dist/esm/classes/queue-getters.js +27 -2
  38. package/dist/esm/classes/queue-getters.js.map +1 -1
  39. package/dist/esm/classes/redis-connection.d.ts +2 -1
  40. package/dist/esm/classes/redis-connection.js +5 -0
  41. package/dist/esm/classes/redis-connection.js.map +1 -1
  42. package/dist/esm/classes/scripts.js +6 -4
  43. package/dist/esm/classes/scripts.js.map +1 -1
  44. package/dist/esm/classes/worker.d.ts +11 -0
  45. package/dist/esm/classes/worker.js +54 -21
  46. package/dist/esm/classes/worker.js.map +1 -1
  47. package/dist/{cjs/commands/addJob-9.lua → esm/commands/addJob-8.lua} +10 -2
  48. package/dist/esm/commands/includes/checkStalledJobs.lua +136 -0
  49. package/dist/esm/commands/includes/getNextDelayedTimestamp.lua +13 -0
  50. package/dist/esm/commands/includes/moveJobFromWaitToActive.lua +1 -4
  51. package/dist/esm/commands/includes/promoteDelayedJobs.lua +57 -0
  52. package/dist/esm/commands/moveStalledJobsToWait-8.lua +4 -102
  53. package/dist/esm/commands/moveToActive-9.lua +67 -0
  54. package/dist/esm/commands/moveToFinished-12.lua +20 -5
  55. package/dist/esm/commands/promote-6.lua +6 -0
  56. package/dist/esm/interfaces/index.d.ts +0 -1
  57. package/dist/esm/interfaces/index.js +0 -1
  58. package/dist/esm/interfaces/index.js.map +1 -1
  59. package/dist/esm/interfaces/sandboxed-job.d.ts +0 -1
  60. package/dist/esm/interfaces/worker-options.d.ts +10 -0
  61. package/package.json +1 -1
  62. package/dist/cjs/classes/compat.d.ts +0 -320
  63. package/dist/cjs/classes/compat.js +0 -682
  64. package/dist/cjs/classes/compat.js.map +0 -1
  65. package/dist/cjs/classes/queue-scheduler.d.ts +0 -75
  66. package/dist/cjs/classes/queue-scheduler.js +0 -199
  67. package/dist/cjs/classes/queue-scheduler.js.map +0 -1
  68. package/dist/cjs/commands/moveToActive-8.lua +0 -54
  69. package/dist/cjs/interfaces/queue-scheduler-options.d.ts +0 -23
  70. package/dist/cjs/interfaces/queue-scheduler-options.js +0 -3
  71. package/dist/cjs/interfaces/queue-scheduler-options.js.map +0 -1
  72. package/dist/esm/classes/compat.d.ts +0 -320
  73. package/dist/esm/classes/compat.js +0 -678
  74. package/dist/esm/classes/compat.js.map +0 -1
  75. package/dist/esm/classes/queue-scheduler.d.ts +0 -75
  76. package/dist/esm/classes/queue-scheduler.js +0 -195
  77. package/dist/esm/classes/queue-scheduler.js.map +0 -1
  78. package/dist/esm/commands/moveToActive-8.lua +0 -54
  79. package/dist/esm/interfaces/queue-scheduler-options.d.ts +0 -23
  80. package/dist/esm/interfaces/queue-scheduler-options.js +0 -2
  81. package/dist/esm/interfaces/queue-scheduler-options.js.map +0 -1
@@ -1,320 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { JobType } from '../types';
4
- import { Job } from './job';
5
- import { QueueEvents } from './queue-events';
6
- import { JobsOptions, Processor, QueueOptions, QueueEventsOptions, QueueSchedulerOptions, RepeatOptions, WorkerOptions } from '../interfaces';
7
- declare type CommonOptions = QueueSchedulerOptions & QueueOptions & WorkerOptions & QueueEventsOptions;
8
- /**
9
- * @deprecated Use Queue class instead {@link https://docs.bullmq.io/guide/queues}
10
- */
11
- export declare class Queue3<T = any> extends EventEmitter {
12
- /**
13
- * The name of the queue
14
- */
15
- name: string;
16
- queueEvents: QueueEvents;
17
- private opts;
18
- private readonly queue;
19
- private worker;
20
- private queueScheduler;
21
- /**
22
- * This is the Queue constructor.
23
- * It creates a new Queue that is persisted in Redis.
24
- * Every time the same queue is instantiated it tries to process all the old jobs
25
- * that may exist from a previous unfinished session.
26
- */
27
- constructor(name: string, opts?: CommonOptions);
28
- /**
29
- * Returns a promise that resolves when Redis is connected and the queue is ready to accept jobs.
30
- * This replaces the `ready` event emitted on Queue in previous versions.
31
- */
32
- isReady(): Promise<this>;
33
- /**
34
- * Defines a processing function for the jobs placed into a given Queue.
35
- *
36
- * The callback is called every time a job is placed in the queue.
37
- * It is passed an instance of the job as first argument.
38
- *
39
- * If the callback signature contains the second optional done argument,
40
- * the callback will be passed a done callback to be called after the job has been completed.
41
- * The done callback can be called with an Error instance, to signal that the job did not complete successfully,
42
- * or with a result as second argument (e.g.: done(null, result);) when the job is successful.
43
- * Errors will be passed as a second argument to the "failed" event; results,
44
- * as a second argument to the "completed" event.
45
- *
46
- * If, however, the callback signature does not contain the done argument,
47
- * a promise must be returned to signal job completion.
48
- * If the promise is rejected, the error will be passed as a second argument to the "failed" event.
49
- * If it is resolved, its value will be the "completed" event's second argument.
50
- */
51
- process(processor: string | Processor<T>): Promise<void>;
52
- add(jobName: string, data: any, opts?: JobsOptions): Promise<Job>;
53
- /**
54
- * Returns a promise that resolves when the queue is paused.
55
- *
56
- * A paused queue will not process new jobs until resumed, but current jobs being processed will continue until
57
- * they are finalized. The pause can be either global or local. If global, all workers in all queue instances
58
- * for a given queue will be paused. If local, just this worker will stop processing new jobs after the current
59
- * lock expires. This can be useful to stop a worker from taking new jobs prior to shutting down.
60
- *
61
- * Pausing a queue that is already paused does nothing.
62
- */
63
- pause(): Promise<void>;
64
- pauseWorker(doNotWaitActive?: boolean): Promise<void>;
65
- /**
66
- * Returns a promise that resolves when the queue is resumed after being paused.
67
- *
68
- * The resume can be either local or global. If global, all workers in all queue instances for a given queue
69
- * will be resumed. If local, only this worker will be resumed. Note that resuming a queue globally will not
70
- * resume workers that have been paused locally; for those, resume(true) must be called directly on their
71
- * instances.
72
- *
73
- * Resuming a queue that is not paused does nothing.
74
- */
75
- resume(): Promise<void>;
76
- resumeWorker(): Promise<void>;
77
- isWorkerPaused(): boolean;
78
- /**
79
- * Returns a promise that returns the number of jobs in the queue, waiting or paused.
80
- * Since there may be other processes adding or processing jobs,
81
- * this value may be true only for a very small amount of time.
82
- */
83
- count(): Promise<number>;
84
- /**
85
- * Empties a queue deleting all the input lists and associated jobs.
86
- */
87
- empty(): Promise<void>;
88
- /**
89
- * Closes the underlying redis client. Use this to perform a graceful shutdown.
90
- *
91
- * `close` can be called from anywhere, with one caveat:
92
- * if called from within a job handler the queue won't close until after the job has been processed
93
- */
94
- close(): Promise<any>;
95
- /**
96
- * Returns a promise that will return the job instance associated with the jobId parameter.
97
- * If the specified job cannot be located, the promise callback parameter will be set to null.
98
- */
99
- getJob(jobId: string): Promise<Job | null>;
100
- /**
101
- * Returns a promise that will return an array with the waiting jobs between start and end.
102
- */
103
- getWaiting(start?: number, end?: number): Promise<Array<Job>>;
104
- /**
105
- * Returns a promise that will return an array with the active jobs between start and end.
106
- */
107
- getActive(start?: number, end?: number): Promise<Array<Job>>;
108
- /**
109
- * Returns a promise that will return an array with the delayed jobs between start and end.
110
- */
111
- getDelayed(start?: number, end?: number): Promise<Array<Job>>;
112
- /**
113
- * Returns a promise that will return an array with the completed jobs between start and end.
114
- */
115
- getCompleted(start?: number, end?: number): Promise<Array<Job>>;
116
- /**
117
- * Returns a promise that will return an array with the failed jobs between start and end.
118
- */
119
- getFailed(start?: number, end?: number): Promise<Array<Job>>;
120
- /**
121
- * Returns JobInformation of repeatable jobs (ordered descending). Provide a start and/or an end
122
- * index to limit the number of results. Start defaults to 0, end to -1 and asc to false.
123
- */
124
- getRepeatableJobs(start?: number, end?: number, asc?: boolean): Promise<JobInformation3[]>;
125
- /**
126
- * ???
127
- */
128
- nextRepeatableJob(name: string, data: any, opts?: JobsOptions, skipCheckExists?: boolean): Promise<Job>;
129
- /**
130
- * Removes a given repeatable job. The RepeatOptions and JobId needs to be the same as the ones
131
- * used for the job when it was added.
132
- *
133
- * name: The name of the to be removed job
134
- */
135
- removeRepeatable(name: string, opts: RepeatOptions): Promise<boolean>;
136
- /**
137
- * Removes a given repeatable job by key.
138
- */
139
- removeRepeatableByKey(repeatJobKey: string): Promise<void>;
140
- /**
141
- * Returns a promise that will return an array of job instances of the given types.
142
- * Optional parameters for range and ordering are provided.
143
- */
144
- getJobs(types: JobType[] | JobType, start?: number, end?: number, asc?: boolean): Promise<Array<Job>>;
145
- getNextJob(): Promise<Job>;
146
- /**
147
- * Returns a object with the logs according to the start and end arguments. The returned count
148
- * value is the total amount of logs, useful for implementing pagination.
149
- */
150
- getJobLogs(jobId: string, start?: number, end?: number): Promise<{
151
- logs: string[];
152
- count: number;
153
- }>;
154
- /**
155
- * Returns a promise that resolves with the job counts for the given queue.
156
- */
157
- getJobCounts(...types: JobType[]): Promise<{
158
- [index: string]: number;
159
- }>;
160
- /**
161
- * Returns a promise that resolves with the job counts for the given queue of the given types.
162
- */
163
- getJobCountByTypes(...types: JobType[]): Promise<number>;
164
- /**
165
- * Returns a promise that resolves with the quantity of completed jobs.
166
- */
167
- getCompletedCount(): Promise<number>;
168
- /**
169
- * Returns a promise that resolves with the quantity of failed jobs.
170
- */
171
- getFailedCount(): Promise<number>;
172
- /**
173
- * Returns a promise that resolves with the quantity of delayed jobs.
174
- */
175
- getDelayedCount(): Promise<number>;
176
- /**
177
- * Returns a promise that resolves with the quantity of waiting jobs.
178
- */
179
- getWaitingCount(): Promise<number>;
180
- /**
181
- * Returns a promise that resolves with the quantity of paused jobs.
182
- */
183
- getPausedCount(): Promise<number>;
184
- /**
185
- * Returns a promise that resolves with the quantity of active jobs.
186
- */
187
- getActiveCount(): Promise<number>;
188
- /**
189
- * Returns a promise that resolves to the quantity of repeatable jobs.
190
- */
191
- getRepeatableCount(): Promise<number>;
192
- /**
193
- * Tells the queue remove all jobs created outside of a grace period in milliseconds.
194
- * You can clean the jobs with the following states: completed, wait (typo for waiting), active, delayed, and failed.
195
- * @param grace - Grace period in milliseconds.
196
- * @param limit - Maximum amount of jobs to clean per call. If not provided will clean all matching jobs.
197
- * @param type - Status of the job to clean. Values are completed, wait,
198
- * active, paused, delayed, and failed. Defaults to completed.
199
- */
200
- clean(grace: number, limit: number, type?: 'completed' | 'wait' | 'active' | 'paused' | 'delayed' | 'failed'): Promise<string[]>;
201
- /**
202
- * Listens to queue events
203
- */
204
- on(event: string, callback: (...args: any[]) => void): this;
205
- /**
206
- * An error occurred
207
- */
208
- on(event: 'error', callback: ErrorEventCallback3): this;
209
- /**
210
- * A Job is waiting to be processed as soon as a worker is idling.
211
- */
212
- on(event: 'waiting', callback: WaitingEventCallback3): this;
213
- /**
214
- * A job has started. You can use `jobPromise.cancel()` to abort it
215
- */
216
- on(event: 'active', callback: ActiveEventCallback3<T>): this;
217
- /**
218
- * A job has been marked as stalled.
219
- * This is useful for debugging job workers that crash or pause the event loop.
220
- */
221
- on(event: 'stalled', callback: StalledEventCallback3<T>): this;
222
- /**
223
- * A job's progress was updated
224
- */
225
- on(event: 'progress', callback: ProgressEventCallback3<T>): this;
226
- /**
227
- * A job successfully completed with a `result`
228
- */
229
- on(event: 'completed', callback: CompletedEventCallback3<T>): this;
230
- /**
231
- * A job failed with `err` as the reason
232
- */
233
- on(event: 'failed', callback: FailedEventCallback3<T>): this;
234
- /**
235
- * The queue has been paused
236
- */
237
- on(event: 'paused', callback: EventCallback3): this;
238
- /**
239
- * The queue has been resumed
240
- */
241
- on(event: 'resumed', callback: EventCallback3): this;
242
- /**
243
- * A job successfully removed.
244
- */
245
- on(event: 'removed', callback: RemovedEventCallback3<T>): this;
246
- /**
247
- * Old jobs have been cleaned from the queue.
248
- * `jobs` is an array of jobs that were removed, and `type` is the type of those jobs.
249
- *
250
- * @see Queue#clean() for details
251
- */
252
- on(event: 'cleaned', callback: CleanedEventCallback3<T>): this;
253
- /**
254
- * Emitted every time the queue has processed all the waiting jobs
255
- * (even if there can be some delayed jobs not yet processed)
256
- */
257
- on(event: 'drained', callback: EventCallback3): this;
258
- once(event: string | symbol, listener: (...args: any[]) => void): this;
259
- off(event: string | symbol, listener?: (...args: any[]) => void): this;
260
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
261
- removeAllListeners(event: string | symbol): this;
262
- /**
263
- * Set clientName to Redis.client
264
- */
265
- setWorkerName(): Promise<any>;
266
- /**
267
- * Returns Redis clients array which belongs to current Queue
268
- */
269
- getWorkers(): Promise<{
270
- [key: string]: string;
271
- }[]>;
272
- /**
273
- * Returns Queue name in base64 encoded format
274
- */
275
- base64Name(): string;
276
- /**
277
- * Returns Queue name with keyPrefix (default: 'bull')
278
- */
279
- clientName(): string;
280
- /**
281
- * Returns Redis clients array which belongs to current Queue from string with all redis clients
282
- *
283
- * @param list - String with all redis clients
284
- */
285
- parseClientList(list: string): {
286
- [key: string]: string;
287
- }[];
288
- retryJob(job: Job): Promise<void>;
289
- private getQueueEvents;
290
- private ensureWorkerCreated;
291
- private attachListener;
292
- detachListener(event: string | symbol, listener?: (...args: any[]) => void): this;
293
- }
294
- export declare type JobStatusClean3 = 'completed' | 'wait' | 'active' | 'delayed' | 'paused' | 'failed';
295
- export interface JobInformation3 {
296
- key: string;
297
- name: string;
298
- id?: string;
299
- endDate?: number;
300
- tz?: string;
301
- cron: string;
302
- next: number;
303
- }
304
- export declare type EventCallback3 = () => void;
305
- export declare type ErrorEventCallback3 = (error: Error) => void;
306
- export interface JobPromise3 {
307
- /**
308
- * Abort this job
309
- */
310
- cancel(): void;
311
- }
312
- export declare type ActiveEventCallback3<T = any> = (job: Job<T>, jobPromise?: JobPromise3) => void;
313
- export declare type StalledEventCallback3<T = any> = (job: Job<T>) => void;
314
- export declare type ProgressEventCallback3<T = any> = (job: Job<T>, progress: any) => void;
315
- export declare type CompletedEventCallback3<T = any> = (job: Job<T>, result: any) => void;
316
- export declare type FailedEventCallback3<T = any> = (job: Job<T>, error: Error) => void;
317
- export declare type CleanedEventCallback3<T = any> = (jobs: Array<Job<T>>, status: JobStatusClean3) => void;
318
- export declare type RemovedEventCallback3<T = any> = (job: Job<T>) => void;
319
- export declare type WaitingEventCallback3 = (jobId: string) => void;
320
- export {};