forked from bee-queue/bee-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
147 lines (121 loc) · 4.26 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
/// <reference types="node" />
/// <reference types="redis" />
import {EventEmitter} from 'events';
import {ClientOpts, RedisClient} from 'redis';
declare class BeeQueue<T = any> extends EventEmitter {
name: string;
keyPrefix: string;
jobs: any;
paused: boolean;
settings: any;
backoffStrategies: Map<string, (job: BeeQueue.Job<T>) => number>;
constructor(name: string, settings?: BeeQueue.QueueSettings);
on(ev: 'ready', fn: () => void): this;
on(ev: 'error', fn: (err: Error) => void): this;
on(ev: 'succeeded', fn: (job: BeeQueue.Job<T>, result: any) => void): this;
on(ev: 'retrying', fn: (job: BeeQueue.Job<T>, err: Error) => void): this;
on(ev: 'failed', fn: (job: BeeQueue.Job<T>, err: Error) => void): this;
on(ev: 'stalled', fn: (jobId: string) => void): this;
on(ev: 'job succeeded', fn: (jobId: string, result: any) => void): this;
on(ev: 'job retrying', fn: (jobId: string, err: Error) => void): this;
on(ev: 'job failed', fn: (jobId: string, err: Error) => void): this;
on(ev: 'job progress', fn: (jobId: string, progress: any) => void): this;
ready(): Promise<this>;
ready(cb?: (err: Error | null) => void): Promise<this>;
isRunning(): boolean;
createJob<U extends T>(data: U): BeeQueue.Job<U>;
getJob(jobId: string, cb: (job: BeeQueue.Job<T>) => void): void;
getJob(jobId: string): Promise<BeeQueue.Job<T>>;
getJobs(
type: string,
page: BeeQueue.Page,
cb: (jobs: BeeQueue.Job<T>[]) => void
): void;
getJobs(type: string, page: BeeQueue.Page): Promise<BeeQueue.Job<T>[]>;
process<U>(handler: (job: BeeQueue.Job<T>) => Promise<U>): void;
process<U>(
handler: (job: BeeQueue.Job<T>, done: BeeQueue.DoneCallback<U>) => void
): void;
process<U>(
concurrency: number,
handler: (job: BeeQueue.Job<T>) => Promise<U>
): void;
process<U>(
concurrency: number,
handler: (job: BeeQueue.Job<T>, done: BeeQueue.DoneCallback<U>) => void
): void;
checkStalledJobs(interval?: number): Promise<number>;
checkStalledJobs(
interval: number,
cb: (err: Error, numStalled: number) => void
): void;
checkStalledJobs(cb: (err: Error, numStalled: number) => void): void;
checkHealth(): Promise<BeeQueue.HealthCheckResult>;
checkHealth(cb: (counts: BeeQueue.HealthCheckResult) => void): void;
close(cb: () => void): void;
close(timeout?: number | null): Promise<void>;
close(timeout: number | undefined | null, cb: () => void): void;
isRunning(): boolean;
ready(): Promise<this>;
ready(cb: () => void): Promise<this>;
removeJob(jobId: string): Promise<void>;
removeJob(jobId: string, cb: () => void): void;
destroy(): Promise<void>;
destroy(cb: () => void): void;
}
declare namespace BeeQueue {
interface QueueSettings {
prefix?: string;
stallInterval?: number;
nearTermWindow?: number;
delayedDebounce?: number;
redis?: ClientOpts | RedisClient;
isWorker?: boolean;
getEvents?: boolean;
sendEvents?: boolean;
storeJobs?: boolean;
ensureScripts?: boolean;
activateDelayedJobs?: boolean;
removeOnSuccess?: boolean;
removeOnFailure?: boolean;
quitCommandClient?: boolean;
redisScanCount?: number;
}
interface Job<T> extends EventEmitter {
id: string;
data: T;
readonly options: any;
queue: BeeQueue<T>;
progress: any;
status: 'created' | 'succeeded' | 'failed' | 'retrying';
on(ev: 'succeeded', fn: (result: any) => void): this;
on(ev: 'retrying', fn: (err: Error) => void): this;
on(ev: 'failed', fn: (err: Error) => void): this;
on(ev: 'progress', fn: (progress: any) => void): this;
setId(id: string): this;
retries(n: number): this;
backoff(strategy: string, delayFactor?: number): this;
delayUntil(dateOrTimestamp: Date | number): this;
timeout(milliseconds: number): this;
save(): Promise<this>;
save(cb: (job: this) => void): void;
reportProgress(p: any): void;
remove(): Promise<this>;
remove(cb: (job: this) => void): void;
}
interface Page {
start?: number;
end?: number;
size?: number;
}
interface HealthCheckResult {
waiting: number;
active: number;
succeeded: number;
failed: number;
delayed: number;
newestJob?: string;
}
type DoneCallback<T> = (error: Error | null, result?: T) => void;
}
export = BeeQueue;