bullmq 3.6.0 → 3.6.2

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 (187) hide show
  1. package/dist/cjs/classes/redis-connection.js +2 -2
  2. package/dist/cjs/classes/redis-connection.js.map +1 -1
  3. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -0
  4. package/dist/esm/classes/redis-connection.js +2 -2
  5. package/dist/esm/classes/redis-connection.js.map +1 -1
  6. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  7. package/dist/{cjs → types}/classes/backoffs.d.ts +0 -0
  8. package/dist/{cjs → types}/classes/child-pool.d.ts +0 -0
  9. package/dist/{cjs → types}/classes/child-processor.d.ts +0 -0
  10. package/dist/{cjs → types}/classes/flow-producer.d.ts +0 -0
  11. package/dist/{cjs → types}/classes/index.d.ts +0 -0
  12. package/dist/{cjs → types}/classes/job.d.ts +0 -0
  13. package/dist/{cjs → types}/classes/master.d.ts +0 -0
  14. package/dist/{cjs → types}/classes/process-utils.d.ts +0 -0
  15. package/dist/{cjs → types}/classes/queue-base.d.ts +0 -0
  16. package/dist/{cjs → types}/classes/queue-events.d.ts +0 -0
  17. package/dist/{cjs → types}/classes/queue-getters.d.ts +0 -0
  18. package/dist/{cjs → types}/classes/queue-keys.d.ts +0 -0
  19. package/dist/{cjs → types}/classes/queue.d.ts +0 -0
  20. package/dist/{cjs → types}/classes/redis-connection.d.ts +0 -0
  21. package/dist/{cjs → types}/classes/repeat.d.ts +0 -0
  22. package/dist/{cjs → types}/classes/sandbox.d.ts +0 -0
  23. package/dist/{cjs → types}/classes/scripts.d.ts +0 -0
  24. package/dist/{cjs → types}/classes/timer-manager.d.ts +0 -0
  25. package/dist/{cjs → types}/classes/unrecoverable-error.d.ts +0 -0
  26. package/dist/{cjs → types}/classes/worker.d.ts +0 -0
  27. package/dist/{cjs → types}/commands/index.d.ts +0 -0
  28. package/dist/{cjs → types}/commands/script-loader.d.ts +0 -0
  29. package/dist/{cjs → types}/enums/error-code.enum.d.ts +0 -0
  30. package/dist/{cjs → types}/enums/index.d.ts +0 -0
  31. package/dist/{cjs → types}/enums/metrics-time.d.ts +0 -0
  32. package/dist/{cjs → types}/index.d.ts +0 -0
  33. package/dist/{cjs → types}/interfaces/advanced-options.d.ts +0 -0
  34. package/dist/{cjs → types}/interfaces/backoff-options.d.ts +0 -0
  35. package/dist/{cjs → types}/interfaces/base-job-options.d.ts +0 -0
  36. package/dist/{cjs → types}/interfaces/child-command.d.ts +0 -0
  37. package/dist/{cjs → types}/interfaces/child-message.d.ts +0 -0
  38. package/dist/{cjs → types}/interfaces/connection.d.ts +0 -0
  39. package/dist/{cjs → types}/interfaces/flow-job.d.ts +0 -0
  40. package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
  41. package/dist/{cjs → types}/interfaces/ioredis-events.d.ts +0 -0
  42. package/dist/{cjs → types}/interfaces/job-json.d.ts +0 -0
  43. package/dist/{cjs → types}/interfaces/keep-jobs.d.ts +0 -0
  44. package/dist/{cjs → types}/interfaces/metrics-options.d.ts +0 -0
  45. package/dist/{cjs → types}/interfaces/metrics.d.ts +0 -0
  46. package/dist/{cjs → types}/interfaces/minimal-job.d.ts +0 -0
  47. package/dist/{cjs → types}/interfaces/parent-command.d.ts +0 -0
  48. package/dist/{cjs → types}/interfaces/parent-message.d.ts +0 -0
  49. package/dist/{cjs → types}/interfaces/parent.d.ts +0 -0
  50. package/dist/{cjs → types}/interfaces/queue-options.d.ts +0 -0
  51. package/dist/{cjs → types}/interfaces/rate-limiter-options.d.ts +0 -0
  52. package/dist/{cjs → types}/interfaces/redis-options.d.ts +0 -0
  53. package/dist/{cjs → types}/interfaces/redis-streams.d.ts +0 -0
  54. package/dist/{cjs → types}/interfaces/repeat-options.d.ts +0 -0
  55. package/dist/{cjs → types}/interfaces/sandboxed-job-processor.d.ts +0 -0
  56. package/dist/{cjs → types}/interfaces/sandboxed-job.d.ts +0 -0
  57. package/dist/{cjs → types}/interfaces/worker-options.d.ts +0 -0
  58. package/dist/{cjs → types}/scripts/addJob-8.d.ts +0 -0
  59. package/dist/{cjs → types}/scripts/changeDelay-3.d.ts +0 -0
  60. package/dist/{cjs → types}/scripts/cleanJobsInSet-2.d.ts +0 -0
  61. package/dist/{cjs → types}/scripts/drain-4.d.ts +0 -0
  62. package/dist/{cjs → types}/scripts/extendLock-2.d.ts +0 -0
  63. package/dist/{cjs → types}/scripts/getCounts-1.d.ts +0 -0
  64. package/dist/{cjs → types}/scripts/getRanges-1.d.ts +0 -0
  65. package/dist/{cjs → types}/scripts/getState-7.d.ts +0 -0
  66. package/dist/{cjs → types}/scripts/getStateV2-7.d.ts +0 -0
  67. package/dist/{cjs → types}/scripts/index.d.ts +0 -0
  68. package/dist/{cjs → types}/scripts/isFinished-3.d.ts +0 -0
  69. package/dist/{cjs → types}/scripts/isJobInList-1.d.ts +0 -0
  70. package/dist/{cjs → types}/scripts/moveJobFromActiveToWait-4.d.ts +0 -0
  71. package/dist/{cjs → types}/scripts/moveStalledJobsToWait-8.d.ts +0 -0
  72. package/dist/{cjs → types}/scripts/moveToActive-9.d.ts +0 -0
  73. package/dist/{cjs → types}/scripts/moveToDelayed-8.d.ts +0 -0
  74. package/dist/{cjs → types}/scripts/moveToFinished-12.d.ts +0 -0
  75. package/dist/{cjs → types}/scripts/moveToWaitingChildren-4.d.ts +0 -0
  76. package/dist/{cjs → types}/scripts/obliterate-2.d.ts +0 -0
  77. package/dist/{cjs → types}/scripts/pause-4.d.ts +0 -0
  78. package/dist/{cjs → types}/scripts/promote-6.d.ts +0 -0
  79. package/dist/{cjs → types}/scripts/releaseLock-1.d.ts +0 -0
  80. package/dist/{cjs → types}/scripts/removeJob-1.d.ts +0 -0
  81. package/dist/{cjs → types}/scripts/removeRepeatable-2.d.ts +0 -0
  82. package/dist/{cjs → types}/scripts/reprocessJob-4.d.ts +0 -0
  83. package/dist/{cjs → types}/scripts/retryJob-8.d.ts +0 -0
  84. package/dist/{cjs → types}/scripts/retryJobs-6.d.ts +0 -0
  85. package/dist/{cjs → types}/scripts/takeLock-1.d.ts +0 -0
  86. package/dist/{cjs → types}/scripts/updateData-1.d.ts +0 -0
  87. package/dist/{cjs → types}/scripts/updateProgress-2.d.ts +0 -0
  88. package/dist/{cjs → types}/types/backoff-strategy.d.ts +0 -0
  89. package/dist/{cjs → types}/types/finished-status.d.ts +0 -0
  90. package/dist/{cjs → types}/types/index.d.ts +0 -0
  91. package/dist/{cjs → types}/types/job-json-sandbox.d.ts +0 -0
  92. package/dist/{cjs → types}/types/job-options.d.ts +0 -0
  93. package/dist/{cjs → types}/types/job-type.d.ts +0 -0
  94. package/dist/{cjs → types}/types/minimal-queue.d.ts +0 -0
  95. package/dist/{cjs → types}/types/repeat-strategy.d.ts +0 -0
  96. package/dist/{cjs → types}/utils.d.ts +0 -0
  97. package/package.json +3 -3
  98. package/dist/esm/classes/backoffs.d.ts +0 -11
  99. package/dist/esm/classes/child-pool.d.ts +0 -22
  100. package/dist/esm/classes/child-processor.d.ts +0 -24
  101. package/dist/esm/classes/flow-producer.d.ts +0 -163
  102. package/dist/esm/classes/index.d.ts +0 -18
  103. package/dist/esm/classes/job.d.ts +0 -341
  104. package/dist/esm/classes/master.d.ts +0 -1
  105. package/dist/esm/classes/process-utils.d.ts +0 -7
  106. package/dist/esm/classes/queue-base.d.ts +0 -67
  107. package/dist/esm/classes/queue-events.d.ts +0 -179
  108. package/dist/esm/classes/queue-getters.d.ts +0 -164
  109. package/dist/esm/classes/queue-keys.d.ts +0 -10
  110. package/dist/esm/classes/queue.d.ts +0 -232
  111. package/dist/esm/classes/redis-connection.d.ts +0 -38
  112. package/dist/esm/classes/repeat.d.ts +0 -25
  113. package/dist/esm/classes/sandbox.d.ts +0 -4
  114. package/dist/esm/classes/scripts.d.ts +0 -101
  115. package/dist/esm/classes/timer-manager.d.ts +0 -17
  116. package/dist/esm/classes/unrecoverable-error.d.ts +0 -10
  117. package/dist/esm/classes/worker.d.ts +0 -196
  118. package/dist/esm/commands/index.d.ts +0 -4
  119. package/dist/esm/commands/script-loader.d.ts +0 -120
  120. package/dist/esm/enums/error-code.enum.d.ts +0 -8
  121. package/dist/esm/enums/index.d.ts +0 -2
  122. package/dist/esm/enums/metrics-time.d.ts +0 -10
  123. package/dist/esm/index.d.ts +0 -6
  124. package/dist/esm/interfaces/advanced-options.d.ts +0 -13
  125. package/dist/esm/interfaces/backoff-options.d.ts +0 -15
  126. package/dist/esm/interfaces/base-job-options.d.ts +0 -92
  127. package/dist/esm/interfaces/child-command.d.ts +0 -5
  128. package/dist/esm/interfaces/child-message.d.ts +0 -6
  129. package/dist/esm/interfaces/connection.d.ts +0 -8
  130. package/dist/esm/interfaces/flow-job.d.ts +0 -20
  131. package/dist/esm/interfaces/index.d.ts +0 -24
  132. package/dist/esm/interfaces/ioredis-events.d.ts +0 -8
  133. package/dist/esm/interfaces/job-json.d.ts +0 -37
  134. package/dist/esm/interfaces/keep-jobs.d.ts +0 -17
  135. package/dist/esm/interfaces/metrics-options.d.ts +0 -12
  136. package/dist/esm/interfaces/metrics.d.ts +0 -9
  137. package/dist/esm/interfaces/minimal-job.d.ts +0 -129
  138. package/dist/esm/interfaces/parent-command.d.ts +0 -10
  139. package/dist/esm/interfaces/parent-message.d.ts +0 -8
  140. package/dist/esm/interfaces/parent.d.ts +0 -20
  141. package/dist/esm/interfaces/queue-options.d.ts +0 -74
  142. package/dist/esm/interfaces/rate-limiter-options.d.ts +0 -12
  143. package/dist/esm/interfaces/redis-options.d.ts +0 -8
  144. package/dist/esm/interfaces/redis-streams.d.ts +0 -4
  145. package/dist/esm/interfaces/repeat-options.d.ts +0 -33
  146. package/dist/esm/interfaces/sandboxed-job-processor.d.ts +0 -5
  147. package/dist/esm/interfaces/sandboxed-job.d.ts +0 -13
  148. package/dist/esm/interfaces/worker-options.d.ts +0 -51
  149. package/dist/esm/scripts/addJob-8.d.ts +0 -5
  150. package/dist/esm/scripts/changeDelay-3.d.ts +0 -5
  151. package/dist/esm/scripts/cleanJobsInSet-2.d.ts +0 -5
  152. package/dist/esm/scripts/drain-4.d.ts +0 -5
  153. package/dist/esm/scripts/extendLock-2.d.ts +0 -5
  154. package/dist/esm/scripts/getCounts-1.d.ts +0 -5
  155. package/dist/esm/scripts/getRanges-1.d.ts +0 -5
  156. package/dist/esm/scripts/getState-7.d.ts +0 -5
  157. package/dist/esm/scripts/getStateV2-7.d.ts +0 -5
  158. package/dist/esm/scripts/index.d.ts +0 -29
  159. package/dist/esm/scripts/isFinished-3.d.ts +0 -5
  160. package/dist/esm/scripts/isJobInList-1.d.ts +0 -5
  161. package/dist/esm/scripts/moveJobFromActiveToWait-4.d.ts +0 -5
  162. package/dist/esm/scripts/moveStalledJobsToWait-8.d.ts +0 -5
  163. package/dist/esm/scripts/moveToActive-9.d.ts +0 -5
  164. package/dist/esm/scripts/moveToDelayed-8.d.ts +0 -5
  165. package/dist/esm/scripts/moveToFinished-12.d.ts +0 -5
  166. package/dist/esm/scripts/moveToWaitingChildren-4.d.ts +0 -5
  167. package/dist/esm/scripts/obliterate-2.d.ts +0 -5
  168. package/dist/esm/scripts/pause-4.d.ts +0 -5
  169. package/dist/esm/scripts/promote-6.d.ts +0 -5
  170. package/dist/esm/scripts/releaseLock-1.d.ts +0 -5
  171. package/dist/esm/scripts/removeJob-1.d.ts +0 -5
  172. package/dist/esm/scripts/removeRepeatable-2.d.ts +0 -5
  173. package/dist/esm/scripts/reprocessJob-4.d.ts +0 -5
  174. package/dist/esm/scripts/retryJob-8.d.ts +0 -5
  175. package/dist/esm/scripts/retryJobs-6.d.ts +0 -5
  176. package/dist/esm/scripts/takeLock-1.d.ts +0 -5
  177. package/dist/esm/scripts/updateData-1.d.ts +0 -5
  178. package/dist/esm/scripts/updateProgress-2.d.ts +0 -5
  179. package/dist/esm/types/backoff-strategy.d.ts +0 -2
  180. package/dist/esm/types/finished-status.d.ts +0 -2
  181. package/dist/esm/types/index.d.ts +0 -7
  182. package/dist/esm/types/job-json-sandbox.d.ts +0 -5
  183. package/dist/esm/types/job-options.d.ts +0 -16
  184. package/dist/esm/types/job-type.d.ts +0 -3
  185. package/dist/esm/types/minimal-queue.d.ts +0 -2
  186. package/dist/esm/types/repeat-strategy.d.ts +0 -2
  187. package/dist/esm/utils.d.ts +0 -43
@@ -1,25 +0,0 @@
1
- import { RepeatBaseOptions, RepeatOptions } from '../interfaces';
2
- import { JobsOptions } from '../types';
3
- import { Job } from './job';
4
- import { QueueBase } from './queue-base';
5
- import { RedisConnection } from './redis-connection';
6
- export declare class Repeat extends QueueBase {
7
- private repeatStrategy;
8
- constructor(name: string, opts?: RepeatBaseOptions, Connection?: typeof RedisConnection);
9
- addNextRepeatableJob<T = any, R = any, N extends string = string>(name: N, data: T, opts: JobsOptions, skipCheckExists?: boolean): Promise<Job<T, R, N>>;
10
- private createNextJob;
11
- removeRepeatable(name: string, repeat: RepeatOptions, jobId?: string): Promise<number>;
12
- removeRepeatableByKey(repeatJobKey: string): Promise<number>;
13
- private keyToData;
14
- getRepeatableJobs(start?: number, end?: number, asc?: boolean): Promise<{
15
- key: string;
16
- name: string;
17
- id: string;
18
- endDate: number;
19
- tz: string;
20
- pattern: string;
21
- next: number;
22
- }[]>;
23
- getRepeatableCount(): Promise<number>;
24
- }
25
- export declare const getNextMillis: (millis: number, opts: RepeatOptions) => number;
@@ -1,4 +0,0 @@
1
- import { ChildPool } from './child-pool';
2
- import { Job } from './job';
3
- declare const sandbox: <T, R, N extends string>(processFile: any, childPool: ChildPool) => (job: Job<T, R, N>) => Promise<R>;
4
- export default sandbox;
@@ -1,101 +0,0 @@
1
- /**
2
- * Includes all the scripts needed by the queue and jobs.
3
- */
4
- /// <reference types="node" />
5
- import { JobJson, JobJsonRaw, MinimalJob, MoveToWaitingChildrenOpts, ParentOpts, RedisClient, KeepJobs } from '../interfaces';
6
- import { JobState, JobType, FinishedStatus, FinishedPropValAttribute, MinimalQueue, RedisJobOptions } from '../types';
7
- import { ChainableCommander } from 'ioredis';
8
- export type JobData = [JobJsonRaw | number, string?];
9
- export declare class Scripts {
10
- protected queue: MinimalQueue;
11
- constructor(queue: MinimalQueue);
12
- isJobInList(listKey: string, jobId: string): Promise<boolean>;
13
- addJob(client: RedisClient, job: JobJson, opts: RedisJobOptions, jobId: string, parentOpts?: ParentOpts): Promise<string>;
14
- pause(pause: boolean): Promise<void>;
15
- private removeRepeatableArgs;
16
- removeRepeatable(repeatJobId: string, repeatJobKey: string): Promise<number>;
17
- remove(jobId: string): Promise<number>;
18
- extendLock(jobId: string, token: string, duration: number): Promise<number>;
19
- updateData<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, data: T): Promise<void>;
20
- updateProgress<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, progress: number | object): Promise<void>;
21
- protected moveToFinishedArgs<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, val: any, propVal: FinishedPropValAttribute, shouldRemove: boolean | number | KeepJobs, target: FinishedStatus, token: string, timestamp: number, fetchNext?: boolean): (string | number | boolean | Buffer)[];
22
- protected moveToFinished<DataType = any, ReturnType = any, NameType extends string = string>(job: MinimalJob<DataType, ReturnType, NameType>, val: any, propVal: FinishedPropValAttribute, shouldRemove: boolean | number | KeepJobs, target: FinishedStatus, token: string, fetchNext: boolean): Promise<any[]>;
23
- finishedErrors(code: number, jobId: string, command: string, state?: string): Error;
24
- private drainArgs;
25
- drain(delayed: boolean): Promise<void>;
26
- private getRangesArgs;
27
- getRanges(types: JobType[], start?: number, end?: number, asc?: boolean): Promise<[string][]>;
28
- private getCountsArgs;
29
- getCounts(types: JobType[]): Promise<number[]>;
30
- moveToCompleted<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, returnvalue: R, removeOnComplete: boolean | number | KeepJobs, token: string, fetchNext: boolean): Promise<any[]>;
31
- moveToFailedArgs<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, failedReason: string, removeOnFailed: boolean | number | KeepJobs, token: string, fetchNext?: boolean): (string | number | boolean | Buffer)[];
32
- isFinished(jobId: string, returnValue?: boolean): Promise<number | [number, string]>;
33
- getState(jobId: string): Promise<JobState | 'unknown'>;
34
- changeDelay(jobId: string, delay: number): Promise<void>;
35
- private changeDelayArgs;
36
- moveToDelayedArgs(jobId: string, timestamp: number, token: string): (string | number)[];
37
- moveToWaitingChildrenArgs(jobId: string, token: string, opts?: MoveToWaitingChildrenOpts): string[];
38
- moveToDelayed(jobId: string, timestamp: number, token?: string): Promise<void>;
39
- /**
40
- * Move parent job to waiting-children state.
41
- *
42
- * @returns true if job is successfully moved, false if there are pending dependencies.
43
- * @throws JobNotExist
44
- * This exception is thrown if jobId is missing.
45
- * @throws JobLockNotExist
46
- * This exception is thrown if job lock is missing.
47
- * @throws JobNotInState
48
- * This exception is thrown if job is not in active state.
49
- */
50
- moveToWaitingChildren(jobId: string, token: string, opts?: MoveToWaitingChildrenOpts): Promise<boolean>;
51
- /**
52
- * Remove jobs in a specific state.
53
- *
54
- * @returns Id jobs from the deleted records.
55
- */
56
- cleanJobsInSet(set: string, timestamp: number, limit?: number): Promise<string[]>;
57
- retryJobArgs(jobId: string, lifo: boolean, token: string): (string | number)[];
58
- protected retryJobsArgs(state: FinishedStatus, count: number, timestamp: number): (string | number)[];
59
- retryJobs(state?: FinishedStatus, count?: number, timestamp?: number): Promise<number>;
60
- /**
61
- * Attempts to reprocess a job
62
- *
63
- * @param job -
64
- * @param state - The expected job state. If the job is not found
65
- * on the provided state, then it's not reprocessed. Supported states: 'failed', 'completed'
66
- *
67
- * @returns Returns a promise that evaluates to a return code:
68
- * 1 means the operation was a success
69
- * 0 means the job does not exist
70
- * -1 means the job is currently locked and can't be retried.
71
- * -2 means the job was not found in the expected set
72
- */
73
- reprocessJob<T = any, R = any, N extends string = string>(job: MinimalJob<T, R, N>, state: 'failed' | 'completed'): Promise<void>;
74
- moveToActive(token: string, jobId?: string): Promise<any[]>;
75
- promote(jobId: string): Promise<number>;
76
- /**
77
- * Looks for unlocked jobs in the active queue.
78
- *
79
- * The job was being worked on, but the worker process died and it failed to renew the lock.
80
- * We call these jobs 'stalled'. This is the most common case. We resolve these by moving them
81
- * back to wait to be re-processed. To prevent jobs from cycling endlessly between active and wait,
82
- * (e.g. if the job handler keeps crashing),
83
- * we limit the number stalled job recoveries to settings.maxStalledCount.
84
- */
85
- moveStalledJobsToWait(): Promise<[string[], string[]]>;
86
- /**
87
- * Moves a job back from Active to Wait.
88
- * This script is used when a job has been manually rate limited and needs
89
- * to be moved back to wait from active status.
90
- *
91
- * @param client - Redis client
92
- * @param jobId - Job id
93
- * @returns
94
- */
95
- moveJobFromActiveToWait(client: ChainableCommander, jobId: string, token: string): any;
96
- obliterate(opts: {
97
- force: boolean;
98
- count: number;
99
- }): Promise<number>;
100
- }
101
- export declare function raw2NextJobData(raw: any[]): any[];
@@ -1,17 +0,0 @@
1
- /**
2
- * Keeps track on timers created with setTimeout to help clearTimeout
3
- * for all timers when no more delayed actions needed
4
- */
5
- export declare class TimerManager {
6
- private readonly timers;
7
- /**
8
- * Creates a new timer and returns its ID.
9
- *
10
- * @param name - Readable name for the timer
11
- * @param delay - Delay in milliseconds
12
- * @param fn - Callback function that is executed after the timer expires
13
- */
14
- setTimer(name: string, delay: number, fn: Function): string;
15
- clearTimer(id: string): void;
16
- clearAllTimers(): void;
17
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * UnrecoverableError
3
- *
4
- * Error to move a job to failed even if the attemptsMade
5
- * are lower than the expected limit.
6
- *
7
- */
8
- export declare class UnrecoverableError extends Error {
9
- constructor(message?: string);
10
- }
@@ -1,196 +0,0 @@
1
- import { GetNextJobOptions, IoredisListener, JobJsonRaw, Processor, RedisClient, WorkerOptions } from '../interfaces';
2
- import { QueueBase } from './queue-base';
3
- import { Repeat } from './repeat';
4
- import { Job } from './job';
5
- import { RedisConnection } from './redis-connection';
6
- import { TimerManager } from './timer-manager';
7
- export interface WorkerListener<DataType = any, ResultType = any, NameType extends string = string> extends IoredisListener {
8
- /**
9
- * Listen to 'active' event.
10
- *
11
- * This event is triggered when a job enters the 'active' state.
12
- */
13
- active: (job: Job<DataType, ResultType, NameType>, prev: string) => void;
14
- /**
15
- * Listen to 'closing' event.
16
- *
17
- * This event is triggered when the worker is closed.
18
- */
19
- closed: () => void;
20
- /**
21
- * Listen to 'closing' event.
22
- *
23
- * This event is triggered when the worker is closing.
24
- */
25
- closing: (msg: string) => void;
26
- /**
27
- * Listen to 'completed' event.
28
- *
29
- * This event is triggered when a job has successfully completed.
30
- */
31
- completed: (job: Job<DataType, ResultType, NameType>, result: ResultType, prev: string) => void;
32
- /**
33
- * Listen to 'drained' event.
34
- *
35
- * This event is triggered when the queue has drained the waiting list.
36
- * Note that there could still be delayed jobs waiting their timers to expire
37
- * and this event will still be triggered as long as the waiting list has emptied.
38
- */
39
- drained: () => void;
40
- /**
41
- * Listen to 'error' event.
42
- *
43
- * This event is triggered when an error is throw.
44
- */
45
- error: (failedReason: Error) => void;
46
- /**
47
- * Listen to 'failed' event.
48
- *
49
- * This event is triggered when a job has thrown an exception.
50
- */
51
- failed: (job: Job<DataType, ResultType, NameType> | undefined, error: Error, prev: string) => void;
52
- /**
53
- * Listen to 'paused' event.
54
- *
55
- * This event is triggered when the queue is paused.
56
- */
57
- paused: () => void;
58
- /**
59
- * Listen to 'progress' event.
60
- *
61
- * This event is triggered when a job updates it progress, i.e. the
62
- * Job##updateProgress() method is called. This is useful to notify
63
- * progress or any other data from within a processor to the rest of the
64
- * world.
65
- */
66
- progress: (job: Job<DataType, ResultType, NameType>, progress: number | object) => void;
67
- /**
68
- * Listen to 'ready' event.
69
- *
70
- * This event is triggered when blockingConnection is ready.
71
- */
72
- ready: () => void;
73
- /**
74
- * Listen to 'resumed' event.
75
- *
76
- * This event is triggered when the queue is resumed.
77
- */
78
- resumed: () => void;
79
- /**
80
- * Listen to 'stalled' event.
81
- *
82
- * This event is triggered when a job has stalled and
83
- * has been moved back to the wait list.
84
- */
85
- stalled: (jobId: string, prev: string) => void;
86
- }
87
- /**
88
- *
89
- * This class represents a worker that is able to process jobs from the queue.
90
- * As soon as the class is instantiated and a connection to Redis is established
91
- * it will start processing jobs.
92
- *
93
- */
94
- export declare class Worker<DataType = any, ResultType = any, NameType extends string = string> extends QueueBase {
95
- readonly opts: WorkerOptions;
96
- readonly id: string;
97
- private drained;
98
- private waiting;
99
- private running;
100
- private blockUntil;
101
- private limitUntil;
102
- protected processFn: Processor<DataType, ResultType, NameType>;
103
- private resumeWorker;
104
- protected paused: Promise<void>;
105
- private _repeat;
106
- private childPool;
107
- protected timerManager: TimerManager;
108
- private blockingConnection;
109
- private processing;
110
- static RateLimitError(): Error;
111
- constructor(name: string, processor?: string | Processor<DataType, ResultType, NameType>, opts?: WorkerOptions, Connection?: typeof RedisConnection);
112
- emit<U extends keyof WorkerListener<DataType, ResultType, NameType>>(event: U, ...args: Parameters<WorkerListener<DataType, ResultType, NameType>[U]>): boolean;
113
- off<U extends keyof WorkerListener<DataType, ResultType, NameType>>(eventName: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): this;
114
- on<U extends keyof WorkerListener<DataType, ResultType, NameType>>(event: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): this;
115
- once<U extends keyof WorkerListener<DataType, ResultType, NameType>>(event: U, listener: WorkerListener<DataType, ResultType, NameType>[U]): this;
116
- protected callProcessJob(job: Job<DataType, ResultType, NameType>, token: string): Promise<ResultType>;
117
- protected createJob(data: JobJsonRaw, jobId: string): Job<DataType, ResultType, NameType>;
118
- /**
119
- *
120
- * Waits until the worker is ready to start processing jobs.
121
- * In general only useful when writing tests.
122
- *
123
- */
124
- waitUntilReady(): Promise<RedisClient>;
125
- set concurrency(concurrency: number);
126
- get repeat(): Promise<Repeat>;
127
- run(): Promise<any[]>;
128
- /**
129
- * Returns a promise that resolves to the next job in queue.
130
- * @param token - worker token to be assigned to retrieved job
131
- * @returns a Job or undefined if no job was available in the queue.
132
- */
133
- getNextJob(token: string, { block }?: GetNextJobOptions): Promise<Job<DataType, ResultType, NameType>>;
134
- /**
135
- * Overrides the rate limit to be active for the next jobs.
136
- *
137
- * @param expireTimeMs - expire time in ms of this rate limit.
138
- */
139
- rateLimit(expireTimeMs: number): Promise<void>;
140
- protected moveToActive(token: string, jobId?: string): Promise<Job<DataType, ResultType, NameType>>;
141
- private waitForJob;
142
- /**
143
- *
144
- * This function is exposed only for testing purposes.
145
- */
146
- delay(milliseconds?: number): Promise<void>;
147
- protected nextJobFromJobData(jobData?: JobJsonRaw, jobId?: string, limitUntil?: number, delayUntil?: number): Promise<Job<DataType, ResultType, NameType>>;
148
- processJob(job: Job<DataType, ResultType, NameType>, token: string, fetchNextCallback?: () => boolean): Promise<void | Job<DataType, ResultType, NameType>>;
149
- /**
150
- *
151
- * Pauses the processing of this queue only for this worker.
152
- */
153
- pause(doNotWaitActive?: boolean): Promise<void>;
154
- /**
155
- *
156
- * Resumes processing of this worker (if paused).
157
- */
158
- resume(): void;
159
- /**
160
- *
161
- * Checks if worker is paused.
162
- *
163
- * @returns true if worker is paused, false otherwise.
164
- */
165
- isPaused(): boolean;
166
- /**
167
- *
168
- * Checks if worker is currently running.
169
- *
170
- * @returns true if worker is running, false otherwise.
171
- */
172
- isRunning(): boolean;
173
- /**
174
- *
175
- * Closes the worker and related redis connections.
176
- *
177
- * This method waits for current jobs to finalize before returning.
178
- *
179
- * @param force - Use force boolean parameter if you do not want to wait for
180
- * current jobs to be processed.
181
- *
182
- * @returns Promise that resolves when the worker has been closed.
183
- */
184
- close(force?: boolean): Promise<void>;
185
- /**
186
- * Returns a promise that resolves when active jobs are cleared
187
- *
188
- * @returns
189
- */
190
- private whenCurrentJobsFinished;
191
- private retryIfFailed;
192
- private runStalledJobsCheck;
193
- private moveStalledJobsToWait;
194
- private notifyFailedJobs;
195
- private moveLimitedBackToWait;
196
- }
@@ -1,4 +0,0 @@
1
- import { ScriptLoader } from './script-loader';
2
- export { ScriptMetadata, Command, ScriptLoaderError } from './script-loader';
3
- declare const scriptLoader: ScriptLoader;
4
- export { ScriptLoader, scriptLoader };
@@ -1,120 +0,0 @@
1
- import { RedisClient } from '../interfaces';
2
- export interface Command {
3
- name: string;
4
- options: {
5
- numberOfKeys: number;
6
- lua: string;
7
- };
8
- }
9
- /**
10
- * Script metadata
11
- */
12
- export interface ScriptMetadata {
13
- /**
14
- * Name of the script
15
- */
16
- name: string;
17
- numberOfKeys?: number;
18
- /**
19
- * The path to the script. For includes, this is the normalized path,
20
- * whereas it may not be normalized for the top-level parent
21
- */
22
- path: string;
23
- /**
24
- * The raw script content
25
- */
26
- content: string;
27
- /**
28
- * A hash of the normalized path for easy replacement in the parent
29
- */
30
- token: string;
31
- /**
32
- * Metadata on the scripts that this script includes
33
- */
34
- includes: ScriptMetadata[];
35
- }
36
- export declare class ScriptLoaderError extends Error {
37
- readonly path: string;
38
- /**
39
- * The include stack
40
- */
41
- readonly includes: string[];
42
- readonly line: number;
43
- readonly position: number;
44
- constructor(message: string, path: string, stack?: string[], line?: number, position?: number);
45
- }
46
- /**
47
- * Lua script loader with include support
48
- */
49
- export declare class ScriptLoader {
50
- /**
51
- * Map an alias to a path
52
- */
53
- private pathMapper;
54
- private clientScripts;
55
- /**
56
- * Cache commands by dir
57
- */
58
- private commandCache;
59
- private rootPath;
60
- constructor();
61
- /**
62
- * Add a script path mapping. Allows includes of the form "<includes>/utils.lua" where `includes` is a user
63
- * defined path
64
- * @param name - the name of the mapping. Note: do not include angle brackets
65
- * @param mappedPath - if a relative path is passed, it's relative to the *caller* of this function.
66
- * Mapped paths are also accepted, e.g. "~/server/scripts/lua" or "<base>/includes"
67
- */
68
- addPathMapping(name: string, mappedPath: string): void;
69
- /**
70
- * Resolve the script path considering path mappings
71
- * @param scriptName - the name of the script
72
- * @param stack - the include stack, for nicer errors
73
- */
74
- resolvePath(scriptName: string, stack?: string[]): string;
75
- /**
76
- * Recursively collect all scripts included in a file
77
- * @param file - the parent file
78
- * @param cache - a cache for file metadata to increase efficiency. Since a file can be included
79
- * multiple times, we make sure to load it only once.
80
- * @param stack - internal stack to prevent circular references
81
- */
82
- private resolveDependencies;
83
- /**
84
- * Parse a (top-level) lua script
85
- * @param filename - the full path to the script
86
- * @param content - the content of the script
87
- * @param cache - cache
88
- */
89
- parseScript(filename: string, content: string, cache?: Map<string, ScriptMetadata>): Promise<ScriptMetadata>;
90
- /**
91
- * Construct the final version of a file by interpolating its includes in dependency order.
92
- * @param file - the file whose content we want to construct
93
- * @param processed - a cache to keep track of which includes have already been processed
94
- */
95
- interpolate(file: ScriptMetadata, processed?: Set<string>): string;
96
- loadCommand(filename: string, cache?: Map<string, ScriptMetadata>): Promise<Command>;
97
- /**
98
- * Load redis lua scripts.
99
- * The name of the script must have the following format:
100
- *
101
- * cmdName-numKeys.lua
102
- *
103
- * cmdName must be in camel case format.
104
- *
105
- * For example:
106
- * moveToFinish-3.lua
107
- *
108
- */
109
- loadScripts(dir?: string, cache?: Map<string, ScriptMetadata>): Promise<Command[]>;
110
- /**
111
- * Attach all lua scripts in a given directory to a client instance
112
- * @param client - redis client to attach script to
113
- * @param pathname - the path to the directory containing the scripts
114
- */
115
- load(client: RedisClient, pathname: string, cache?: Map<string, ScriptMetadata>): Promise<void>;
116
- /**
117
- * Clears the command cache
118
- */
119
- clearCache(): void;
120
- }
@@ -1,8 +0,0 @@
1
- export declare enum ErrorCode {
2
- JobNotExist = -1,
3
- JobLockNotExist = -2,
4
- JobNotInState = -3,
5
- JobPendingDependencies = -4,
6
- ParentJobNotExist = -5,
7
- JobLockMismatch = -6
8
- }
@@ -1,2 +0,0 @@
1
- export * from './error-code.enum';
2
- export * from './metrics-time';
@@ -1,10 +0,0 @@
1
- export declare enum MetricsTime {
2
- ONE_MINUTE = 1,
3
- FIVE_MINUTES = 5,
4
- FIFTEEN_MINUTES = 15,
5
- THIRTY_MINUTES = 30,
6
- ONE_HOUR = 60,
7
- ONE_WEEK = 10080,
8
- TWO_WEEKS = 20160,
9
- ONE_MONTH = 80640
10
- }
@@ -1,6 +0,0 @@
1
- export * from './classes';
2
- export * from './commands';
3
- export * from './enums';
4
- export * from './interfaces';
5
- export * from './types';
6
- export * from './utils';
@@ -1,13 +0,0 @@
1
- import { BackoffStrategy, RepeatStrategy } from '../types';
2
- export interface AdvancedRepeatOptions {
3
- /**
4
- * A custom cron strategy.
5
- */
6
- repeatStrategy?: RepeatStrategy;
7
- }
8
- export interface AdvancedOptions extends AdvancedRepeatOptions {
9
- /**
10
- * A custom backoff strategy.
11
- */
12
- backoffStrategy?: BackoffStrategy;
13
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Settings for backing off failed jobs.
3
- *
4
- * @see {@link https://docs.bullmq.io/guide/retrying-failing-jobs}
5
- */
6
- export interface BackoffOptions {
7
- /**
8
- * Name of the backoff strategy.
9
- */
10
- type: 'fixed' | 'exponential' | (string & {});
11
- /**
12
- * Delay in milliseconds.
13
- */
14
- delay?: number;
15
- }
@@ -1,92 +0,0 @@
1
- import { RepeatOptions, KeepJobs, BackoffOptions } from './';
2
- export interface DefaultJobOptions {
3
- /**
4
- * Timestamp when the job was created.
5
- * @defaultValue Date.now()
6
- */
7
- timestamp?: number;
8
- /**
9
- * Ranges from 1 (highest priority) to MAX_INT (lowest priority). Note that
10
- * using priorities has a slight impact on performance,
11
- * so do not use it if not required.
12
- */
13
- priority?: number;
14
- /**
15
- * An amount of milliseconds to wait until this job can be processed.
16
- * Note that for accurate delays, worker and producers
17
- * should have their clocks synchronized.
18
- * @defaultValue 0
19
- */
20
- delay?: number;
21
- /**
22
- * The total number of attempts to try the job until it completes.
23
- * @defaultValue 0
24
- */
25
- attempts?: number;
26
- /**
27
- * Backoff setting for automatic retries if the job fails
28
- */
29
- backoff?: number | BackoffOptions;
30
- /**
31
- * If true, adds the job to the right of the queue instead of the left (default false)
32
- *
33
- * @see {@link https://docs.bullmq.io/guide/jobs/lifo}
34
- */
35
- lifo?: boolean;
36
- /**
37
- * If true, removes the job when it successfully completes
38
- * When given a number, it specifies the maximum amount of
39
- * jobs to keep, or you can provide an object specifying max
40
- * age and/or count to keep.
41
- * Default behavior is to keep the job in the completed set.
42
- */
43
- removeOnComplete?: boolean | number | KeepJobs;
44
- /**
45
- * If true, removes the job when it fails after all attempts.
46
- * When given a number, it specifies the maximum amount of
47
- * jobs to keep, or you can provide an object specifying max
48
- * age and/or count to keep.
49
- */
50
- removeOnFail?: boolean | number | KeepJobs;
51
- /**
52
- * Maximum amount of log entries that will be preserved
53
- */
54
- keepLogs?: number;
55
- /**
56
- * Limits the amount of stack trace lines that will be recorded in the stacktrace.
57
- */
58
- stackTraceLimit?: number;
59
- /**
60
- * Limits the size in bytes of the job's data payload (as a JSON serialized string).
61
- */
62
- sizeLimit?: number;
63
- }
64
- export interface BaseJobOptions extends DefaultJobOptions {
65
- /**
66
- * Repeat this job, for example based on a `cron` schedule.
67
- */
68
- repeat?: RepeatOptions;
69
- /**
70
- * Internal property used by repeatable jobs to save base repeat job key.
71
- */
72
- repeatJobKey?: string;
73
- /**
74
- * Override the job ID - by default, the job ID is a unique
75
- * integer, but you can use this setting to override it.
76
- * If you use this option, it is up to you to ensure the
77
- * jobId is unique. If you attempt to add a job with an id that
78
- * already exists, it will not be added.
79
- */
80
- jobId?: string;
81
- /**
82
- *
83
- */
84
- parent?: {
85
- id: string;
86
- queue: string;
87
- };
88
- /**
89
- * Internal property used by repeatable jobs.
90
- */
91
- prevMillis?: number;
92
- }
@@ -1,5 +0,0 @@
1
- export declare enum ChildCommand {
2
- Init = 0,
3
- Start = 1,
4
- Stop = 2
5
- }
@@ -1,6 +0,0 @@
1
- import { ParentCommand } from './parent-command';
2
- export interface ChildMessage {
3
- cmd: ParentCommand;
4
- value?: any;
5
- err?: Record<string, any>;
6
- }
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { Cluster, Redis } from 'ioredis';
4
- export type RedisClient = Redis | Cluster;
5
- export interface IConnection extends EventEmitter {
6
- waitUntilReady(): Promise<boolean>;
7
- client: Promise<RedisClient>;
8
- }