pg-boss 9.0.2 → 10.0.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/timekeeper.js CHANGED
@@ -134,8 +134,7 @@ class Timekeeper extends EventEmitter {
134
134
  async checkSchedulesAsync () {
135
135
  const opts = {
136
136
  retryLimit: 2,
137
- retentionSeconds: 60,
138
- onComplete: false
137
+ retentionSeconds: 60
139
138
  }
140
139
 
141
140
  await this.manager.sendDebounced(queues.CRON, null, opts, 60)
@@ -145,8 +144,8 @@ class Timekeeper extends EventEmitter {
145
144
  if (this.stopped) return
146
145
 
147
146
  try {
148
- if (this.config.__test__throw_clock_monitoring) {
149
- throw new Error(this.config.__test__throw_clock_monitoring)
147
+ if (this.config.__test__throw_cron_processing) {
148
+ throw new Error(this.config.__test__throw_cron_processing)
150
149
  }
151
150
 
152
151
  const items = await this.getSchedules()
@@ -186,8 +185,7 @@ class Timekeeper extends EventEmitter {
186
185
  async send (job) {
187
186
  const options = {
188
187
  singletonKey: job.name,
189
- singletonSeconds: 60,
190
- onComplete: false
188
+ singletonSeconds: 60
191
189
  }
192
190
 
193
191
  await this.manager.send(queues.SEND_IT, job, options)
package/src/tools.js ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = {
2
+ delay
3
+ }
4
+
5
+ function delay (ms, error) {
6
+ const { setTimeout } = require('timers/promises')
7
+ const ac = new AbortController()
8
+
9
+ const promise = new Promise((resolve, reject) => {
10
+ setTimeout(ms, null, { signal: ac.signal })
11
+ .then(() => {
12
+ if (error) {
13
+ reject(new Error(error))
14
+ } else {
15
+ resolve()
16
+ }
17
+ })
18
+ .catch(resolve)
19
+ })
20
+
21
+ promise.abort = () => {
22
+ if (!ac.signal.aborted) {
23
+ ac.abort()
24
+ }
25
+ }
26
+
27
+ return promise
28
+ }
package/src/worker.js CHANGED
@@ -1,4 +1,4 @@
1
- const delay = require('delay')
1
+ const { delay } = require('./tools')
2
2
 
3
3
  const WORKER_STATES = {
4
4
  created: 'created',
@@ -34,7 +34,7 @@ class Worker {
34
34
  this.beenNotified = true
35
35
 
36
36
  if (this.loopDelayPromise) {
37
- this.loopDelayPromise.clear()
37
+ this.loopDelayPromise.abort()
38
38
  }
39
39
  }
40
40
 
@@ -91,7 +91,7 @@ class Worker {
91
91
  this.state = WORKER_STATES.stopping
92
92
 
93
93
  if (this.loopDelayPromise) {
94
- this.loopDelayPromise.clear()
94
+ this.loopDelayPromise.abort()
95
95
  }
96
96
  }
97
97
  }
package/types.d.ts CHANGED
@@ -20,20 +20,20 @@ declare namespace PgBoss {
20
20
  }
21
21
 
22
22
  interface QueueOptions {
23
- uuid?: "v1" | "v4";
24
23
  monitorStateIntervalSeconds?: number;
25
24
  monitorStateIntervalMinutes?: number;
26
25
  }
27
26
 
28
27
  interface SchedulingOptions {
29
- noScheduling?: boolean;
28
+ schedule?: boolean;
30
29
 
31
30
  clockMonitorIntervalSeconds?: number;
32
31
  clockMonitorIntervalMinutes?: number;
33
32
  }
34
33
 
35
34
  interface MaintenanceOptions {
36
- noSupervisor?: boolean;
35
+ supervise?: boolean;
36
+ migrate?: boolean;
37
37
 
38
38
  deleteAfterSeconds?: number;
39
39
  deleteAfterMinutes?: number;
@@ -56,11 +56,6 @@ declare namespace PgBoss {
56
56
  & RetentionOptions
57
57
  & RetryOptions
58
58
  & JobPollingOptions
59
- & CompletionOptions
60
-
61
- interface CompletionOptions {
62
- onComplete?: boolean;
63
- }
64
59
 
65
60
  interface ExpirationOptions {
66
61
  expireInSeconds?: number;
@@ -82,14 +77,15 @@ declare namespace PgBoss {
82
77
  }
83
78
 
84
79
  interface JobOptions {
80
+ id?: string,
85
81
  priority?: number;
86
82
  startAfter?: number | string | Date;
87
83
  singletonKey?: string;
88
- useSingletonQueue?: boolean;
89
84
  singletonSeconds?: number;
90
85
  singletonMinutes?: number;
91
86
  singletonHours?: number;
92
87
  singletonNextSlot?: boolean;
88
+ deadLetter?: string;
93
89
  }
94
90
 
95
91
  interface ConnectionOptions {
@@ -98,7 +94,7 @@ declare namespace PgBoss {
98
94
 
99
95
  type InsertOptions = ConnectionOptions;
100
96
 
101
- type SendOptions = JobOptions & ExpirationOptions & RetentionOptions & RetryOptions & CompletionOptions & ConnectionOptions;
97
+ type SendOptions = JobOptions & ExpirationOptions & RetentionOptions & RetryOptions & ConnectionOptions;
102
98
 
103
99
  type ScheduleOptions = SendOptions & { tz?: string }
104
100
 
@@ -109,7 +105,7 @@ declare namespace PgBoss {
109
105
 
110
106
  interface CommonJobFetchOptions {
111
107
  includeMetadata?: boolean;
112
- enforceSingletonQueueActiveLimit?: boolean;
108
+ priority?: boolean;
113
109
  }
114
110
 
115
111
  type JobFetchOptions = CommonJobFetchOptions & {
@@ -127,7 +123,6 @@ declare namespace PgBoss {
127
123
 
128
124
  type FetchOptions = {
129
125
  includeMetadata?: boolean;
130
- enforceSingletonQueueActiveLimit?: boolean;
131
126
  } & ConnectionOptions;
132
127
 
133
128
  interface WorkHandler<ReqData> {
@@ -183,7 +178,7 @@ declare namespace PgBoss {
183
178
 
184
179
  interface JobWithMetadata<T = object> extends Job<T> {
185
180
  priority: number;
186
- state: 'created' | 'retry' | 'active' | 'completed' | 'expired' | 'cancelled' | 'failed';
181
+ state: 'created' | 'retry' | 'active' | 'completed' | 'cancelled' | 'failed';
187
182
  retrylimit: number;
188
183
  retrycount: number;
189
184
  retrydelay: number;
@@ -198,7 +193,7 @@ declare namespace PgBoss {
198
193
  createdon: Date;
199
194
  completedon: Date | null;
200
195
  keepuntil: Date;
201
- oncomplete: boolean,
196
+ deadletter: string,
202
197
  output: object
203
198
  }
204
199
 
@@ -214,7 +209,7 @@ declare namespace PgBoss {
214
209
  singletonKey?: string;
215
210
  expireInSeconds?: number;
216
211
  keepUntil?: Date | string;
217
- onComplete?: boolean
212
+ deadLetter?: string;
218
213
  }
219
214
 
220
215
  interface MonitorState {
@@ -223,7 +218,6 @@ declare namespace PgBoss {
223
218
  retry: number;
224
219
  active: number;
225
220
  completed: number;
226
- expired: number;
227
221
  cancelled: number;
228
222
  failed: number;
229
223
  }
@@ -236,7 +230,7 @@ declare namespace PgBoss {
236
230
  id: string,
237
231
  name: string,
238
232
  options: WorkOptions,
239
- state: 'created' | 'retry' | 'active' | 'completed' | 'expired' | 'cancelled' | 'failed',
233
+ state: 'created' | 'active' | 'stopping' | 'stopped'
240
234
  count: number,
241
235
  createdOn: Date,
242
236
  lastFetchedOn: Date,
@@ -250,7 +244,8 @@ declare namespace PgBoss {
250
244
  interface StopOptions {
251
245
  destroy?: boolean,
252
246
  graceful?: boolean,
253
- timeout?: number
247
+ timeout?: number,
248
+ wait?: boolean
254
249
  }
255
250
 
256
251
  interface OffWorkOptions {
@@ -300,10 +295,6 @@ declare class PgBoss extends EventEmitter {
300
295
  sendAfter(name: string, data: object, options: PgBoss.SendOptions, dateString: string): Promise<string | null>;
301
296
  sendAfter(name: string, data: object, options: PgBoss.SendOptions, seconds: number): Promise<string | null>;
302
297
 
303
- sendOnce(name: string, data: object, options: PgBoss.SendOptions, key: string): Promise<string | null>;
304
-
305
- sendSingleton(name: string, data: object, options: PgBoss.SendOptions): Promise<string | null>;
306
-
307
298
  sendThrottled(name: string, data: object, options: PgBoss.SendOptions, seconds: number): Promise<string | null>;
308
299
  sendThrottled(name: string, data: object, options: PgBoss.SendOptions, seconds: number, key: string): Promise<string | null>;
309
300
 
@@ -320,9 +311,6 @@ declare class PgBoss extends EventEmitter {
320
311
  work<ReqData>(name: string, options: PgBoss.BatchWorkOptions & { includeMetadata: true }, handler: PgBoss.BatchWorkWithMetadataHandler<ReqData>): Promise<string>;
321
312
  work<ReqData>(name: string, options: PgBoss.BatchWorkOptions, handler: PgBoss.BatchWorkHandler<ReqData>): Promise<string>;
322
313
 
323
- onComplete(name: string, handler: Function): Promise<string>;
324
- onComplete(name: string, options: PgBoss.WorkOptions, handler: Function): Promise<string>;
325
-
326
314
  offWork(name: string): Promise<void>;
327
315
  offWork(options: PgBoss.OffWorkOptions): Promise<void>;
328
316
 
@@ -338,19 +326,11 @@ declare class PgBoss extends EventEmitter {
338
326
  publish(event: string, data: object): Promise<string[]>;
339
327
  publish(event: string, data: object, options: PgBoss.SendOptions): Promise<string[]>;
340
328
 
341
- offComplete(name: string): Promise<void>;
342
- offComplete(options: PgBoss.OffWorkOptions): Promise<void>;
343
-
344
329
  fetch<T>(name: string): Promise<PgBoss.Job<T> | null>;
345
330
  fetch<T>(name: string, batchSize: number): Promise<PgBoss.Job<T>[] | null>;
346
331
  fetch<T>(name: string, batchSize: number, options: PgBoss.FetchOptions & { includeMetadata: true }): Promise<PgBoss.JobWithMetadata<T>[] | null>;
347
332
  fetch<T>(name: string, batchSize: number, options: PgBoss.FetchOptions): Promise<PgBoss.Job<T>[] | null>;
348
333
 
349
- fetchCompleted<T>(name: string): Promise<PgBoss.Job<T> | null>;
350
- fetchCompleted<T>(name: string, batchSize: number): Promise<PgBoss.Job<T>[] | null>;
351
- fetchCompleted<T>(name: string, batchSize: number, options: PgBoss.FetchOptions & { includeMetadata: true }): Promise<PgBoss.JobWithMetadata<T>[] | null>;
352
- fetchCompleted<T>(name: string, batchSize: number, options: PgBoss.FetchOptions): Promise<PgBoss.Job<T>[] | null>;
353
-
354
334
  cancel(id: string, options?: PgBoss.ConnectionOptions): Promise<void>;
355
335
  cancel(ids: string[], options?: PgBoss.ConnectionOptions): Promise<void>;
356
336
 
@@ -368,13 +348,15 @@ declare class PgBoss extends EventEmitter {
368
348
  getQueueSize(name: string, options?: object): Promise<number>;
369
349
  getJobById(id: string, options?: PgBoss.ConnectionOptions): Promise<PgBoss.JobWithMetadata | null>;
370
350
 
351
+ createQueue(name: string, policy: 'standard' | 'short' | 'singleton' | 'stately'): Promise<void>;
371
352
  deleteQueue(name: string): Promise<void>;
372
- deleteAllQueues(): Promise<void>;
353
+ purgeQueue(name: string): Promise<void>;
373
354
  clearStorage(): Promise<void>;
374
355
 
375
356
  archive(): Promise<void>;
376
357
  purge(): Promise<void>;
377
358
  expire(): Promise<void>;
359
+ maintain(): Promise<void>;
378
360
 
379
361
  schedule(name: string, cron: string, data?: object, options?: PgBoss.ScheduleOptions): Promise<void>;
380
362
  unschedule(name: string): Promise<void>;
package/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "schema": 20
2
+ "schema": 21
3
3
  }