1
- // Type definitions for bull 3.3
1
+ // Type definitions for bull 3.4
2
2
// Project: https://github.com/OptimalBits/bull
3
3
// Definitions by: Bruno Grieder <https://github.com/bgrieder>
4
4
// Cameron Crothers <https://github.com/JProgrammer>
10
10
// Bond Akinmade <https://github.com/bondz>
11
11
// Wuha Team <https://github.com/wuha-team>
12
12
// Alec Brunelle <https://github.com/aleccool213>
13
+ // Dan Manastireanu <https://github.com/danmana>
13
14
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
14
15
// TypeScript Version: 2.8
15
16
@@ -23,9 +24,9 @@ import * as Promise from "bluebird";
23
24
*/
24
25
declare const Bull : {
25
26
( queueName : string , opts ?: Bull . QueueOptions ) : Bull . Queue ;
26
- ( queueName : string , url ? : string ) : Bull . Queue ; // tslint:disable-line unified-signatures
27
+ ( queueName : string , url : string , opts ?: Bull . QueueOptions ) : Bull . Queue ; // tslint:disable-line unified-signatures
27
28
new ( queueName : string , opts ?: Bull . QueueOptions ) : Bull . Queue ;
28
- new ( queueName : string , url ? : string ) : Bull . Queue ; // tslint:disable-line unified-signatures
29
+ new ( queueName : string , url : string , opts ?: Bull . QueueOptions ) : Bull . Queue ; // tslint:disable-line unified-signatures
29
30
} ;
30
31
31
32
declare namespace Bull {
@@ -92,6 +93,12 @@ declare namespace Bull {
92
93
backoffStrategies ?: {
93
94
[ key : string ] : ( attemptsMade : number , err : typeof Error ) => number ;
94
95
} ;
96
+
97
+ /**
98
+ * A timeout for when the queue is in `drained` state (empty waiting for jobs).
99
+ * It is used when calling `queue.getNextJob()`, which will pass it to `.brpoplpush` on the Redis client.
100
+ */
101
+ drainDelay ?: number ;
95
102
}
96
103
97
104
type DoneCallback = ( error ?: Error | null , value ?: any ) => void ;
@@ -141,13 +148,30 @@ declare namespace Bull {
141
148
*/
142
149
retry ( ) : Promise < void > ;
143
150
151
+ /**
152
+ * Ensure this job is never ran again even if attemptsMade is less than job.attempts.
153
+ */
154
+ discard ( ) : Promise < void > ;
155
+
144
156
/**
145
157
* Returns a promise that resolves to the returned data when the job has been finished.
146
158
* TODO: Add a watchdog to check if the job has finished periodically.
147
159
* since pubsub does not give any guarantees.
148
160
*/
149
161
finished ( ) : Promise < any > ;
150
162
163
+ /**
164
+ * Moves a job to the `completed` queue. Pulls a job from 'waiting' to 'active'
165
+ * and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
166
+ */
167
+ moveToCompleted ( returnValue ?: string , ignoreLock ?: boolean ) : Promise < [ any , JobId ] | null > ;
168
+
169
+ /**
170
+ * Moves a job to the `failed` queue. Pulls a job from 'waiting' to 'active'
171
+ * and returns a tuple containing the next jobs data and id. If no job is in the `waiting` queue, returns null.
172
+ */
173
+ moveToFailed ( errorInfo : { message : string ; } , ignoreLock ?: boolean ) : Promise < [ any , JobId ] | null > ;
174
+
151
175
/**
152
176
* Promotes a job that is currently "delayed" to the "waiting" state and executed as soon as possible.
153
177
*/
@@ -205,6 +229,11 @@ declare namespace Bull {
205
229
* Cron pattern specifying when the job should execute
206
230
*/
207
231
cron : string ;
232
+
233
+ /**
234
+ * Start date when the repeat job should start repeating (only with cron).
235
+ */
236
+ startDate ?: Date | string | number ;
208
237
}
209
238
210
239
interface EveryRepeatOptions extends RepeatOptions {
@@ -273,6 +302,11 @@ declare namespace Bull {
273
302
* Default behavior is to keep the job in the completed set.
274
303
*/
275
304
removeOnFail ?: boolean ;
305
+
306
+ /**
307
+ * Limits the amount of stack trace lines that will be recorded in the stacktrace.
308
+ */
309
+ stackTraceLimit ?: number ;
276
310
}
277
311
278
312
interface JobCounts {
@@ -618,6 +652,11 @@ declare namespace Bull {
618
652
*/
619
653
on ( event : 'error' , callback : ErrorEventCallback ) : this;
620
654
655
+ /**
656
+ * A Job is waiting to be processed as soon as a worker is idling.
657
+ */
658
+ on ( event : 'waiting' , callback : WaitingEventCallback ) : this;
659
+
621
660
/**
622
661
* A job has started. You can use `jobPromise.cancel()` to abort it
623
662
*/
@@ -654,13 +693,24 @@ declare namespace Bull {
654
693
*/
655
694
on ( event : 'resumed' , callback : EventCallback ) : this; // tslint:disable-line unified-signatures
656
695
696
+ /**
697
+ * A job successfully removed.
698
+ */
699
+ on ( event : 'removed' , callback : RemovedEventCallback < T > ) : this;
700
+
657
701
/**
658
702
* Old jobs have been cleaned from the queue.
659
703
* `jobs` is an array of jobs that were removed, and `type` is the type of those jobs.
660
704
*
661
705
* @see Queue#clean() for details
662
706
*/
663
707
on ( event : 'cleaned' , callback : CleanedEventCallback < T > ) : this;
708
+
709
+ /**
710
+ * Emitted every time the queue has processed all the waiting jobs
711
+ * (even if there can be some delayed jobs not yet processed)
712
+ */
713
+ on ( event : 'drained' , callback : EventCallback ) : this; // tslint:disable-line unified-signatures
664
714
}
665
715
666
716
type EventCallback = ( ) => void ;
@@ -685,6 +735,10 @@ declare namespace Bull {
685
735
type FailedEventCallback < T = any > = ( job : Job < T > , error : Error ) => void ;
686
736
687
737
type CleanedEventCallback < T = any > = ( jobs : Array < Job < T > > , status : JobStatus ) => void ;
738
+
739
+ type RemovedEventCallback < T = any > = ( job : Job < T > ) => void ;
740
+
741
+ type WaitingEventCallback = ( jobId : JobId ) => void ;
688
742
}
689
743
690
744
export = Bull ;
0 commit comments