forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kue.d.ts
149 lines (134 loc) · 4.79 KB
/
kue.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
// Type definitions for kue 0.9.x
// Project: https://github.com/Automattic/kue
// Definitions by: Nicholas Penree <http://github.com/drudge>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../redis/redis.d.ts" />
/// <reference path="../express/express.d.ts" />
declare module "kue" {
import events = require('events');
import express = require('express');
import redis = require('redis');
export class Queue extends events.EventEmitter {
name: string;
id: string;
promoter: any;
workers: Worker[];
shuttingDown: boolean;
client: redis.RedisClient;
testMode: TestMode;
static singleton: Queue;
constructor(options: Object);
create(type: string, data: Object): Job;
createJob(type: string, data: Object): Job;
promote(ms?: number): void;
setupTimer(): void;
checkJobPromotion(ms: number): void;
checkActiveJobTtl(ttlOptions: Object): void;
watchStuckJobs(ms: number): void;
setting(name: string, fn: Function): Queue;
process(type: string, n?: number, fn?: Function): void;
shutdown(timeout: number, type: string, fn: Function): Queue;
types(fn: Function): Queue;
state(string: string, fn: Function): Queue;
workTime(fn: Function): Queue;
cardByType(type: string, state: string, fn: Function): Queue;
card(state: string, fn: Function): Queue;
complete(fn: Function): Queue;
failed(fn: Function): Queue;
inactive(fn: Function): Queue;
active(fn: Function): Queue;
delayed(fn: Function): Queue;
completeCount(type: string, fn: Function): Queue;
failedCount(type: string, fn: Function): Queue;
inactiveCount(type: string, fn: Function): Queue;
activeCount(type: string, fn: Function): Queue;
delayedCount(type: string, fn: Function): Queue;
}
interface Priorities {
low: number;
normal: number;
medium: number;
high: number;
critical: number;
}
export class Job extends events.EventEmitter {
public id: number;
public type: string;
public data: any;
public client: redis.RedisClient;
private _max_attempts;
static priorities: Priorities;
static disableSearch: boolean;
static jobEvents: boolean;
static get(id: number, fn: Function): void;
static remove(id: number, fn?: Function): void;
static removeBadJob(id: number): void;
static log(id: number, fn: Function): void;
static range(from: number, to: number, order: string, fn: Function): void;
static rangeByState(state: string, from: number, to: number, order: string, fn: Function): void;
static rangeByType(type: string, state: string, from: number, to: number, order: string, fn: Function): void;
constructor(type: string, data?: any);
toJSON(): Object;
log(str: string): Job;
set(key: string, val: string, fn?: Function): Job;
get(key: string, fn?: Function): Job;
progress(complete: number, total: number, data?: any): Job;
delay(ms:number|Date): Job;
removeOnComplete(param: any): void;
backoff(param: any): void;
ttl(param: any): void;
private _getBackoffImpl(): void;
priority(level: string|number): Job;
attempt(fn: Function): Job;
reattempt(attempt: number, fn?: Function): void;
attempts(n: number): Job;
searchKeys(keys: string[]|string): Job;
remove(fn?: Function): Job;
state(state: string, fn?: Function): Job;
error(err: Error): Job;
complete(fn?: Function): Job;
failed(fn?: Function): Job;
inactive(fn?: Function): Job;
active(fn?: Function): Job;
delayed(fn?: Function): Job;
save(fn?: Function): Job;
update(fn?: Function): Job;
subscribe(fn?: Function): Job;
}
class Worker extends events.EventEmitter {
queue: Queue;
type: string;
client: redis.RedisClient;
job: Job;
constructor(queue: Queue, type: string);
start(fn: Function): Worker;
error(err: Error, job: Job): Worker;
failed(job: Job, theErr: Object, fn?: Function): Worker;
process(job: Job, fn: Function): Worker;
private zpop(key: string, fn: Function): void;
private getJob(fn: Function): void;
idle(): Worker;
shutdown(timeout: number, fn: Function): void;
emitJobEvent(event: Object, job: Job, arg1: any, arg2: any): void;
resume(): boolean;
}
interface Redis {
configureFactory(options: Object, queue: Queue): void;
createClient(): redis.RedisClient;
createClientFactory(options: Object): redis.RedisClient;
client(): redis.RedisClient;
pubsubClient(): redis.RedisClient;
reset(): void;
}
interface TestMode {
jobs: Job[];
enter(): void;
exit(): void;
clear(): void;
}
export var app: express.Application;
export var redis: Redis;
export var workers: Worker[];
export function createQueue(options?: Object): Queue;
}