-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathindex.d.ts
327 lines (304 loc) · 10.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import * as Kue from 'kue-unique'; // eslint-disable-line import/no-extraneous-dependencies
declare class Scheduler extends Kue.Queue {
static createQueue(options: {
prefix?: string;
redis?: {
port: number;
host: string;
[key: string]: any; // see https://github.com/NodeRedis/node_redis#rediscreateclient
};
restore?: boolean;
worker?: boolean;
skipConfig?: boolean;
}): Scheduler;
/**
* @function
* @description generate an expiration key that is used to track job scheduling
* @return {String} a job expiry key
* @private
*/
_getJobExpiryKey(uuid: string): string;
/**
* @function
* @description check if job exists and its ttl has not timeout
* @param {String} jobExpiryKey valid job expiry key
* @param {Function} done a function to invoke on success or error
* @return {Boolean} whether job already scheduled or not
* @private
*/
_isJobExpiryKey(uuid: string): boolean;
/**
* @function
* @description check if job exists and its ttl has not timeout
* @param {String} jobExpiryKey valid job expiry key
* @param {Function} done a function to invoke on success or error
* @return {Boolean} whether job already scheduled or not
* @private
*/
_isJobAlreadyScheduled(jobExpiryKey: string, done?: Function): boolean;
/**
* @function
* @description generate job uuid from job definition
* @param {Object} jobDefinition valid job definition
* @return {String} job uuid
* @private
*/
_generateJobUUID(jobDefinition: object): string;
/**
* @function
* @description generate job uuid from job expiry key or job data key
* @return {String} a scheduled job uuid
* @private
*/
_getJobUUID(key: string): string;
/**
* @function
* @description generate a storage key for the scheduled job data
* @return {String} a key to retrieve a scheduled job data
* @private
*/
_getJobDataKey(uuid: string): string;
/**
* @function
* @description generate a lock for the scheduling of a job
* @return {String} a key to lock on based on the UUID
* @private
*/
_getJobLockKey(uuid: string): string;
/**
* @function
* @description save scheduled job data into redis backend
* @param {String} jobDataKey valid job data key
* @param {Object} jobData valid job data
* @param {Function} done a callback to invoke on success or failure
* @private
*/
_saveJobData(jobDataKey: string, jobData: object, done?: Function);
/**
* @function
* @description retrieved saved scheduled job data from redis backend
* @param {String} jobDataKey valid job data key
* @param {Function} done a callback to invoke on success or failure
* @return {Object} job data if found else error
* @private
*/
_readJobData(jobDataKey: string, done?: Function): object;
/**
* @function
* @description Enable redis expiry keys notifications
* @public
*/
enableExpiryNotifications();
/**
* @function
* @description parse date.js valid string and return a date object
* @param {String} str a valid date.js date string
* @param {Function} done a callback to invoke on error or success
* @private
*/
_parse(str: string, done?: Function);
/**
* @function
* @description instantiate a kue job from a job definition hash
* @param {Object} jobDefinition valid kue job attributes
* @param {Function} done a callback to invoke on error or success
* @private
*/
_buildJob(jobDefinition: object, done?: Function);
/**
* @function
* @description compute next run time of the given job data
* @param {Object} jobData valid job data
* @param {Function} done a callback to invoke on success or failure
* @private
*/
_computeNextRunTime(jobData: object, done?: Function);
/**
* @function
* @description respond to job key expiry events
* @param {String} jobExpiryKey valid job expiry key
* @private
*/
onJobKeyExpiry(jobExpiryKey: string);
/**
* @function
* @description subscribe to key expiry events
* @private
*/
_subscribe();
/**
* @function
* @description get a key to subscribe on for expired events
* @return {String} key for expired events
* @private
*/
_getExpiredSubscribeKey(): string;
/**
* @function
* @description schedule a job to run every after a specified interval
*
* If an error occur, it will be emitted using `schedule error` key
* with error passed as first parameter on event.
*
* If job schedule successfully, it will be emitted using
* `schedule success` key with job instance passed as a first parameter
* on event.
*
* @param {String} interval scheduled interval in either human interval or
* cron format
* @param {Job} job valid kue job instance which has not been saved
* @param {Function} [done] a callback to invoke on success or failure
* @example
* 1. create non-unique job
* var job = Queue
* .createJob('every', data)
* .attempts(3)
* .priority('normal');
*
* Queue.every('2 seconds', job, done?);
*
* 2. create unique job
* var job = Queue
* .create('every', data)
* .attempts(3)
* .priority('normal')
* .unique(<unique_key>);
*
* Queue.every('2 seconds', job, done?);
* @public
*/
every(interval: string, job: Kue.Job, done?: Function);
/**
* @function
* @description schedules a job to run once at a given time.
* `when` can be a `Date` or a valid `date.js string`
* such as `tomorrow at 5pm`.
*
* If an error occur, it will be emitted using `schedule error` key
* with error passed as first parameter on event.
*
* If job schedule successfully, it will be emitted using
* `schedule success` key with job instance passed as a first parameter
* on event.
*
* @param {Date|String} when when should this job run
* @param {Job} jobDefinition valid kue job instance which has not been saved
* @param {Fuction} [done] a callback to invoke on success or error
* @example
* 1. create non-unique job
* var job = Queue
* .createJob('schedule', data)
* .attempts(3)
* .priority('normal');
*
* Queue.schedule('2 seconds from now', job, done?);
*
* 2. create unique job
* var job = Queue
* .create('schedule', data)
* .attempts(3)
* .priority('normal')
* .unique(<unique_key>);
*
* Queue.schedule('2 seconds from now', job, done?);
* @public
*/
schedule(when: Date | string, job: Kue.Job, done?: Function);
/**
* @function
* @description schedule a job to be executed immediatelly after being saved.
*
* If an error occur, it will be emitted using `schedule error` key
* with error passed as first parameter on event.
*
* If job schedule successfully, it will be emitted using
* `schedule success` key with job instance passed as a first parameter
* on event.
*
* @param {Job} job a valid kue job instance which has not been saved
* @param {Function} [done] a callback to invoke on success or failure
* @example
* 1. create non-unique job
* var job = Queue
* .createJob('now', data)
* .attempts(3)
* .priority('normal');
*
* Queue.now(job);
*
* 2. create unique job
* var job = Queue
* .create('now', data)
* .attempts(3)
* .priority('normal')
* .unique(<unique_key>);
*
* Queue.now(job);
* @public
*/
now(job: Kue.Job, done?: Function);
/**
* @function
* @description graceful shutdown
* @return {this} for chaining
* @api public
*/
shutdown(): this;
/**
* @function
* @description remove existing job and its schedule
* @param {Number|Job|Object} criteria a job id, job instance or criteria
* to be used
* @param {Function} [done] a callback to invoke on success or error
* @public
*/
removeJob(criteria: number | Kue.Job | object, done?: Function);
/**
* @function
* @description cleanup and reset current kue and kue-scheduler states
* @param {Function} done a callback to invoke on success or failure
* @public
*/
clear(done?: Function);
/**
* @function
* @description obtain all previous schedule job data
* @param {Function} done a callback to invoke on sucess or failure
* @return {[Object]} collection of all job data
* @since 0.7.0
*/
_getAllJobData(done?: Function);
/**
* @function
* @description restore scheduled works
* @since 0.7.0
*/
restore(done?: Function);
create(type: string, data: Object): Kue.Job;
createJob(type: string, data: Object): Kue.Job;
promote(ms?: number): void;
setupTimer(): void;
checkJobPromotion(ms: number): void;
checkActiveJobTtl(ttlOptions: Object): void;
watchStuckJobs(ms: number): void;
setting(name: string, fn: Function): Scheduler;
process(type: string, n?: number | Kue.ProcessCallback, fn?: Kue.ProcessCallback): void;
shutdown(timeout: number, fn: Function): Scheduler;
shutdown(timeout: number, type: string, fn: Function): Scheduler;
types(fn: Function): Scheduler;
state(string: string, fn: Function): Scheduler;
workTime(fn: Function): Scheduler;
cardByType(type: string, state: string, fn: Function): Scheduler;
card(state: string, fn: Function): Scheduler;
complete(fn: Function): Scheduler;
failed(fn: Function): Scheduler;
inactive(fn: Function): Scheduler;
active(fn: Function): Scheduler;
delayed(fn: Function): Scheduler;
completeCount(type: string, fn: Function): Scheduler;
failedCount(type: string, fn: Function): Scheduler;
inactiveCount(type: string, fn: Function): Scheduler;
activeCount(type: string, fn: Function): Scheduler;
delayedCount(type: string, fn: Function): Scheduler;
}
export = Scheduler;