forked from timgit/pg-boss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
157 lines (138 loc) · 5.34 KB
/
types.d.ts
File metadata and controls
157 lines (138 loc) · 5.34 KB
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
// Type definitions for pg-boss
declare namespace PgBoss {
interface Db {
executeSql(text: string, values: any[]): Promise<{ rows: any[]; rowCount: number }>;
}
interface DatabaseOptions {
application_name?: string;
database?: string;
user?: string;
password?: string;
host?: string;
port?: number;
schema?: string;
ssl?: boolean;
connectionString?: string;
poolSize?: number;
max?: number;
db?: Db;
}
interface JobCreationOptions {
uuid?: "v1" | "v4";
}
interface JobFetchOptions {
newJobCheckInterval?: number;
newJobCheckIntervalSeconds?: number;
}
interface JobExpirationOptions {
expireCheckInterval?: number;
expireCheckIntervalSeconds?: number;
expireCheckIntervalMinutes?: number;
}
interface JobArchiveOptions {
archiveCompletedJobsEvery?: string;
archiveCheckInterval?: number;
archiveCheckIntervalSeconds?: number;
archiveCheckIntervalMinutes?: number;
deleteArchivedJobsEvery?: string;
deleteCheckInterval?: number;
}
type ConstructorOptions = DatabaseOptions & JobCreationOptions & JobFetchOptions & JobExpirationOptions & JobArchiveOptions;
interface PublishOptions {
priority?: number;
startAfter?: number | string | Date;
singletonKey?: string;
singletonSeconds?: number;
singletonMinutes?: number;
singletonHours?: number;
singletonNextSlot?: boolean;
retryLimit?: number;
retryDelay?: number;
retryBackoff?: boolean;
expireIn?: string;
}
interface SubscribeOptions {
teamSize?: number;
teamConcurrency?: number;
batchSize?: number;
newJobCheckInterval?: number;
newJobCheckIntervalSeconds?: number;
}
interface SubscribeHandler<ReqData, ResData> {
(job: PgBoss.JobWithDoneCallback<ReqData, ResData>, done: PgBoss.JobDoneCallback<ResData>): void;
}
interface Request {
name: string;
data?: object;
options?: PublishOptions;
}
interface JobDoneCallback<T> {
(err?: Error | null, data?: T): void;
}
interface Job<T = object> {
id: string;
name: string;
data: T;
}
interface JobWithDoneCallback<ReqData, ResData> extends Job<ReqData> {
done: JobDoneCallback<ResData>;
}
interface MonitorStates {
created: number;
retry: number;
active: number;
completed: number;
expired: number;
cancelled: number;
failed: number;
queues: object;
}
}
declare class PgBoss {
constructor(connectionString: string);
constructor(options: PgBoss.ConstructorOptions);
static getConstructionPlans(schema: string): string;
static getMigrationPlans(schema: string, version: string, uninstall: boolean): string;
on(event: "error", handler: (error: Error) => void): void;
on(event: "archived", handler: (count: number) => void): void;
on(event: "expired", handler: (count: number) => void): void;
on(event: "monitor-states", handler: (monitorStates: PgBoss.MonitorStates) => void): void;
start(): Promise<PgBoss>;
stop(): Promise<void>;
connect(): Promise<PgBoss>;
disconnect(): Promise<void>;
publish(request: PgBoss.Request): Promise<string | null>;
publish(name: string, data: object): Promise<string | null>;
publish(name: string, data: object, options: PgBoss.PublishOptions): Promise<string | null>;
publishAfter(name: string, data: object, options: PgBoss.PublishOptions, date: Date): Promise<string | null>;
publishAfter(name: string, data: object, options: PgBoss.PublishOptions, dateString: string): Promise<string | null>;
publishAfter(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise<string | null>;
publishOnce(name: string, data: object, options: PgBoss.PublishOptions, key: string): Promise<string | null>;
publishThrottled(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise<string | null>;
publishThrottled(name: string, data: object, options: PgBoss.PublishOptions, seconds: number, key: string): Promise<string | null>;
publishDebounced(name: string, data: object, options: PgBoss.PublishOptions, seconds: number): Promise<string | null>;
publishDebounced(name: string, data: object, options: PgBoss.PublishOptions, seconds: number, key: string): Promise<string | null>;
subscribe<ReqData, ResData>(name: string, handler: PgBoss.SubscribeHandler<ReqData, ResData>): Promise<void>;
subscribe<ReqData, ResData>(
name: string,
options: PgBoss.SubscribeOptions,
handler: PgBoss.SubscribeHandler<ReqData, ResData>
): Promise<void>;
unsubscribe(name: string): Promise<boolean>;
onComplete(name: string, handler: Function): Promise<void>;
onComplete(name: string, options: PgBoss.SubscribeOptions, handler: Function): Promise<void>;
offComplete(name: string): Promise<boolean>;
fetch<T>(name: string): Promise<PgBoss.Job<T> | null>;
fetch<T>(name: string, batchSize: number): Promise<PgBoss.Job<T>[] | null>;
fetchCompleted<T>(name: string): Promise<PgBoss.Job<T> | null>;
fetchCompleted<T>(name: string, batchSize: number): Promise<PgBoss.Job<T>[] | null>;
cancel(id: string): Promise<void>;
cancel(ids: string[]): Promise<void>;
complete(id: string): Promise<void>;
complete(id: string, data: object): Promise<void>;
complete(ids: string[]): Promise<void>;
fail(id: string): Promise<void>;
fail(id: string, data: object): Promise<void>;
fail(ids: string[]): Promise<void>;
}
export = PgBoss;