@wavezync/nestjs-pgboss 4.0.0 → 5.0.0

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/README.MD CHANGED
@@ -72,14 +72,20 @@ You can access the `PgBoss` instance directly via `pgBossService.boss`
72
72
  ```ts
73
73
  import { Injectable, Logger } from '@nestjs/common';
74
74
  import { Job } from '@wavezync/nestjs-pgboss';
75
+ import { JobWithMetadata } from 'pg-boss';
76
+
77
+ interface MyJobData {
78
+ id: number;
79
+ name: string;
80
+ }
75
81
 
76
82
  @Injectable()
77
83
  export class MyJobHandler {
78
84
  private readonly logger = new Logger(MyJobHandler.name);
79
85
 
80
86
  @Job('my-job')
81
- async handleMyJob(jobs: any[]) {
82
- this.logger.log(`Handling ${jobs.length} job(s)`);
87
+ async handleMyJob(jobs: JobWithMetadata<MyJobData>[]) {
88
+ this.logger.log(`Processing ${jobs.length} job(s)`);
83
89
  }
84
90
  }
85
91
 
@@ -1,4 +1,4 @@
1
- import { JobOptions, WorkOptions } from "pg-boss";
1
+ import { ScheduleOptions, WorkOptions } from "pg-boss";
2
2
  export declare const JOB_NAME = "JOB_NAME";
3
3
  export declare const JOB_OPTIONS = "JOB_OPTIONS";
4
4
  export declare const CRON_EXPRESSION = "CRON_EXPRESSION";
@@ -7,4 +7,4 @@ export declare const PG_BOSS_JOB_METADATA = "PG_BOSS_JOB_METADATA";
7
7
  export declare const WORK_NAME = "WORK_NAME";
8
8
  export declare const WORK_OPTIONS = "WORK_OPTIONS";
9
9
  export declare function Job<_TData extends object = any>(name: string, options?: WorkOptions): (target: any, key: string, descriptor: PropertyDescriptor) => void;
10
- export declare function CronJob<_TData extends object = any>(name: string, cron: string, options?: JobOptions): (target: any, key: string, descriptor: PropertyDescriptor) => void;
10
+ export declare function CronJob<_TData extends object = any>(name: string, cron: string, options?: ScheduleOptions): (target: any, key: string, descriptor: PropertyDescriptor) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"job.decorator.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BAAW,EAAC,gBAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QACrD,IAAA,oBAAW,EAAC,uBAAe,EAAE,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC5D,IAAA,oBAAW,EAAC,oBAAY,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAC5D,IAAA,oBAAW,EAAC,4BAAoB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CACxE,MAAM,EACN,GAAG,EACH,UAAU,CACX,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,7 +1,7 @@
1
- import { JobOptions } from "pg-boss";
1
+ import { WorkOptions, ScheduleOptions } from "pg-boss";
2
2
  export interface HandlerMetadata {
3
3
  jobName: string;
4
- workOptions?: JobOptions;
4
+ workOptions?: WorkOptions;
5
5
  cronExpression?: string;
6
- cronOptions?: JobOptions;
6
+ cronOptions?: ScheduleOptions;
7
7
  }
@@ -1,6 +1,9 @@
1
1
  import { ModuleMetadata, Type } from "@nestjs/common";
2
2
  import { ConstructorOptions } from "pg-boss";
3
- export type PgBossModuleOptions = ConstructorOptions;
3
+ export interface PgBossModuleOptions extends ConstructorOptions {
4
+ retryLimit?: number;
5
+ retryDelay?: number;
6
+ }
4
7
  export interface PgBossOptionsFactory {
5
8
  createPgBossOptions(): Promise<PgBossModuleOptions> | PgBossModuleOptions;
6
9
  }
@@ -1,5 +1,5 @@
1
1
  import { DynamicModule, OnModuleInit, OnApplicationBootstrap, OnModuleDestroy } from "@nestjs/common";
2
- import PgBoss from "pg-boss";
2
+ import { PgBoss } from "pg-boss";
3
3
  import { PgBossModuleAsyncOptions } from "./interfaces/pgboss-module-options.interface";
4
4
  import { HandlerScannerService } from "./handler-scanner.service";
5
5
  export declare class PgBossModule implements OnModuleInit, OnApplicationBootstrap, OnModuleDestroy {
@@ -11,15 +11,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
14
  var PgBossModule_1;
18
15
  Object.defineProperty(exports, "__esModule", { value: true });
19
16
  exports.PgBossModule = void 0;
20
17
  const common_1 = require("@nestjs/common");
21
18
  const core_1 = require("@nestjs/core");
22
- const pg_boss_1 = __importDefault(require("pg-boss"));
19
+ const pg_boss_1 = require("pg-boss");
23
20
  const rxjs_1 = require("rxjs");
24
21
  const pgboss_service_1 = require("./pgboss.service");
25
22
  const consts_1 = require("./utils/consts");
@@ -39,9 +36,7 @@ let PgBossModule = PgBossModule_1 = class PgBossModule {
39
36
  const pgBossProvider = {
40
37
  provide: consts_1.PGBOSS_TOKEN,
41
38
  useFactory: async (pgBossOptions) => {
42
- const boss = await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(() => new pg_boss_1.default({
43
- connectionString: pgBossOptions.connectionString,
44
- }).start()).pipe((0, handleRetry_1.handleRetry)(pgBossOptions.retryAttempts, pgBossOptions.retryDelay, pgBossOptions.verboseRetryLog)));
39
+ const boss = await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(() => new pg_boss_1.PgBoss(pgBossOptions).start()).pipe((0, handleRetry_1.handleRetry)(pgBossOptions.retryLimit, pgBossOptions.retryDelay)));
45
40
  boss.on("error", (error) => {
46
41
  logger.error(`PgBoss error: ${error.message}`, error.stack);
47
42
  });
@@ -114,7 +109,7 @@ exports.PgBossModule = PgBossModule = PgBossModule_1 = __decorate([
114
109
  providers: [core_1.MetadataScanner, handler_scanner_service_1.HandlerScannerService],
115
110
  }),
116
111
  __param(0, (0, common_1.Inject)(consts_1.PGBOSS_TOKEN)),
117
- __metadata("design:paramtypes", [pg_boss_1.default,
112
+ __metadata("design:paramtypes", [pg_boss_1.PgBoss,
118
113
  handler_scanner_service_1.HandlerScannerService])
119
114
  ], PgBossModule);
120
115
  //# sourceMappingURL=pgboss.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pgboss.module.js","sourceRoot":"","sources":["../lib/pgboss.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,2CASwB;AACxB,uCAA+C;AAC/C,sDAA6B;AAC7B,+BAA4C;AAC5C,qDAAiD;AACjD,2CAAsE;AAKtE,uEAAkE;AAClE,qDAAgD;AAMzC,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAKvB,YACwB,IAA6B,EAClC,qBAA4C;QADtB,SAAI,GAAJ,IAAI,CAAQ;QAClC,0BAAqB,GAArB,qBAAqB,CAAuB;QAJ9C,WAAM,GAAG,IAAI,eAAM,CAAC,eAAM,CAAC,CAAC;QAM3C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAiC;QACnD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,eAAM,CAAC,CAAC;QAElC,MAAM,cAAc,GAAG;YACrB,OAAO,EAAE,qBAAY;YACrB,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAa,EAC9B,IAAA,YAAK,EAAC,GAAG,EAAE,CACT,IAAI,iBAAM,CAAC;oBACT,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;iBACjD,CAAC,CAAC,KAAK,EAAE,CACX,CAAC,IAAI,CACJ,IAAA,yBAAW,EACT,aAAa,CAAC,aAAa,EAC3B,aAAa,CAAC,UAAU,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C,YAAY,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACzB,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,YAAY;QACxB,MAAM,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,EAAE,CAAC;IAC7D,CAAC;CACF,CAAA;AAvGY,oCAAY;uBAAZ,YAAY;IAJxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,sBAAe,EAAE,+CAAqB,CAAC;KACpD,CAAC;IAOG,WAAA,IAAA,eAAM,EAAC,qBAAY,CAAC,CAAA;qCAAwB,gBAAM;QACX,+CAAqB;GAPpD,YAAY,CAuGxB"}
@@ -1,10 +1,10 @@
1
- import PgBoss, { WorkWithMetadataHandler } from "pg-boss";
1
+ import { WorkWithMetadataHandler, PgBoss, SendOptions, ScheduleOptions, WorkOptions } from "pg-boss";
2
2
  export declare class PgBossService {
3
3
  private pgBoss;
4
4
  constructor(boss: PgBoss);
5
5
  get boss(): PgBoss;
6
- scheduleJob<TData extends object>(name: string, data: TData, options?: PgBoss.SendOptions): Promise<void>;
7
- scheduleCronJob<TData extends object>(name: string, cron: string, data?: TData, options?: PgBoss.ScheduleOptions): Promise<void>;
8
- registerCronJob<TData extends object>(name: string, cron: string, handler: WorkWithMetadataHandler<TData>, data?: TData, options?: PgBoss.ScheduleOptions): Promise<void>;
9
- registerJob<TData extends object>(name: string, handler: WorkWithMetadataHandler<TData>, options?: PgBoss.WorkOptions): Promise<void>;
6
+ scheduleJob<TData extends object>(name: string, data: TData, options?: SendOptions): Promise<void>;
7
+ scheduleCronJob<TData extends object>(name: string, cron: string, data?: TData, options?: ScheduleOptions): Promise<void>;
8
+ registerCronJob<TData extends object>(name: string, cron: string, handler: WorkWithMetadataHandler<TData>, data?: TData, options?: ScheduleOptions): Promise<void>;
9
+ registerJob<TData extends object>(name: string, handler: WorkWithMetadataHandler<TData>, options?: WorkOptions): Promise<void>;
10
10
  }
@@ -11,13 +11,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
14
  Object.defineProperty(exports, "__esModule", { value: true });
18
15
  exports.PgBossService = void 0;
19
16
  const common_1 = require("@nestjs/common");
20
- const pg_boss_1 = __importDefault(require("pg-boss"));
17
+ const pg_boss_1 = require("pg-boss");
21
18
  const common_2 = require("@nestjs/common");
22
19
  const consts_1 = require("./utils/consts");
23
20
  const helpers_1 = require("./utils/helpers");
@@ -50,6 +47,6 @@ exports.PgBossService = PgBossService;
50
47
  exports.PgBossService = PgBossService = __decorate([
51
48
  (0, common_1.Injectable)(),
52
49
  __param(0, (0, common_2.Inject)(consts_1.PGBOSS_TOKEN)),
53
- __metadata("design:paramtypes", [pg_boss_1.default])
50
+ __metadata("design:paramtypes", [pg_boss_1.PgBoss])
54
51
  ], PgBossService);
55
52
  //# sourceMappingURL=pgboss.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pgboss.service.js","sourceRoot":"","sources":["../lib/pgboss.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,sDAA0D;AAC1D,2CAAwC;AACxC,2CAA8C;AAC9C,6CAAmD;AAG5C,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGxB,YAAkC,IAAY;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QAC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ACZ,OAAyB;QAEzB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACpB,IAAI,kCACC,IAAA,0BAAgB,EAAC,OAAO,CAAC,KAAE,eAAe,EAAE,IAAI,KACrD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CACf,IAAY,EACZ,OAAuC,EACvC,OAAqB;QAErB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACpB,IAAI,kCACC,OAAO,KAAE,eAAe,EAAE,IAAI,KACnC,OAAO,CACR,CAAC;IACJ,CAAC;CACF,CAAA;AA1DY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,eAAM,EAAC,qBAAY,CAAC,CAAA;qCAAO,gBAAM;GAHnC,aAAa,CA0DzB"}
@@ -1 +1 @@
1
- export declare function handleRetry(retryAttempts?: number, retryDelay?: number, verbose?: boolean, toRetry?: (err: any) => boolean): <T>(source: import("rxjs").Observable<T>) => import("rxjs").Observable<T>;
1
+ export declare function handleRetry(retryAttempts?: number, retryDelay?: number, toRetry?: (err: any) => boolean): <T>(source: import("rxjs").Observable<T>) => import("rxjs").Observable<T>;
@@ -3,16 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleRetry = handleRetry;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
- const consts_1 = require("./consts");
7
- const common_1 = require("@nestjs/common");
8
- function handleRetry(retryAttempts = 9, retryDelay = 3000, verbose = false, toRetry = (_err) => true) {
9
- const logger = new common_1.Logger(consts_1.LOGGER);
6
+ function handleRetry(retryAttempts = 9, retryDelay = 3000, toRetry = (_err) => true) {
10
7
  return (source) => source.pipe((0, operators_1.retryWhen)((attempts) => attempts.pipe((0, operators_1.mergeMap)((error, index) => {
11
8
  const includeError = toRetry(error);
12
9
  if (includeError) {
13
- if (verbose) {
14
- logger.warn(`Attempt ${index + 1}: Retrying in ${retryDelay / 1000} seconds...`);
15
- }
16
10
  if (index + 1 >= retryAttempts) {
17
11
  return (0, rxjs_1.throwError)(() => new Error(error.message));
18
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handleRetry.js","sourceRoot":"","sources":["../../lib/utils/handleRetry.ts"],"names":[],"mappings":";;AAKA,kCAoCC;AAzCD,+BAAsC;AACtC,8CAA4D;AAC5D,qCAAkC;AAClC,2CAAwC;AAExC,SAAgB,WAAW,CACzB,aAAa,GAAG,CAAC,EACjB,UAAU,GAAG,IAAI,EACjB,OAAO,GAAG,KAAK,EACf,UAAiC,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAEpD,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,eAAM,CAAC,CAAC;IAElC,OAAO,CAAI,MAAoC,EAAE,EAAE,CACjD,MAAM,CAAC,IAAI,CACT,IAAA,qBAAS,EAAC,CAAC,QAAQ,EAAE,EAAE,CACrB,QAAQ,CAAC,IAAI,CACX,IAAA,oBAAQ,EAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACxB,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAEpC,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,IAAI,CACT,WAAW,KAAK,GAAG,CAAC,iBAClB,UAAU,GAAG,IACf,aAAa,CACd,CAAC;YACJ,CAAC;YAED,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC;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jC,CAAC,CAAC,CACH,CACF,CACF,CAAC;AACN,CAAC"}
@@ -1,3 +1,3 @@
1
- import PgBoss from "pg-boss";
2
- export declare function transformOptions(options?: PgBoss.WorkOptions | PgBoss.ScheduleOptions): any;
1
+ import { WorkOptions, ScheduleOptions } from "pg-boss";
2
+ export declare function transformOptions(options?: WorkOptions | ScheduleOptions): any;
3
3
  export declare function normalizeJob(job: any): any;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../lib/utils/helpers.ts"],"names":[],"mappings":";;AAEA,4CAYC;AAED,oCAKC;AAnBD,SAAgB,gBAAgB,CAC9B,OAAqD;IAErD,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,kBAAkB,qBAAa,OAAO,CAAE,CAAC;IAE/C,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACzC,kBAAkB,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAgB,YAAY,CAAC,GAAQ;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1C,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../lib/utils/helpers.ts"],"names":[],"mappings":";;AAEA,4CAUC;AAED,oCAKC;AAjBD,SAAgB,gBAAgB,CAAC,OAAuC;IACtE,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,kBAAkB,qBAAa,OAAO,CAAE,CAAC;IAE/C,IAAI,OAAQ,OAAe,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClD,kBAAkB,CAAC,QAAQ,GAAI,OAAe,CAAC,QAAQ,GAAG,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAgB,YAAY,CAAC,GAAQ;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1C,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { SetMetadata } from "@nestjs/common";
2
- import { JobOptions, WorkOptions } from "pg-boss";
2
+ import { ScheduleOptions, WorkOptions } from "pg-boss";
3
3
 
4
4
  export const JOB_NAME = "JOB_NAME";
5
5
  export const JOB_OPTIONS = "JOB_OPTIONS";
@@ -27,7 +27,7 @@ export function Job<_TData extends object = any>(
27
27
  export function CronJob<_TData extends object = any>(
28
28
  name: string,
29
29
  cron: string,
30
- options: JobOptions = {},
30
+ options: ScheduleOptions = {},
31
31
  ) {
32
32
  return (target: any, key: string, descriptor: PropertyDescriptor) => {
33
33
  SetMetadata(JOB_NAME, name)(target, key, descriptor);
@@ -1,8 +1,8 @@
1
- import { JobOptions } from "pg-boss";
1
+ import { WorkOptions, ScheduleOptions } from "pg-boss";
2
2
 
3
3
  export interface HandlerMetadata {
4
4
  jobName: string;
5
- workOptions?: JobOptions;
5
+ workOptions?: WorkOptions;
6
6
  cronExpression?: string;
7
- cronOptions?: JobOptions;
7
+ cronOptions?: ScheduleOptions;
8
8
  }
@@ -1,7 +1,10 @@
1
1
  import { ModuleMetadata, Type } from "@nestjs/common";
2
2
  import { ConstructorOptions } from "pg-boss";
3
3
 
4
- export type PgBossModuleOptions = ConstructorOptions;
4
+ export interface PgBossModuleOptions extends ConstructorOptions {
5
+ retryLimit?: number;
6
+ retryDelay?: number;
7
+ }
5
8
 
6
9
  export interface PgBossOptionsFactory {
7
10
  createPgBossOptions(): Promise<PgBossModuleOptions> | PgBossModuleOptions;
@@ -9,16 +9,17 @@ import {
9
9
  Inject,
10
10
  } from "@nestjs/common";
11
11
  import { MetadataScanner } from "@nestjs/core";
12
- import PgBoss from "pg-boss";
12
+ import { PgBoss } from "pg-boss";
13
13
  import { defer, lastValueFrom } from "rxjs";
14
14
  import { PgBossService } from "./pgboss.service";
15
15
  import { LOGGER, PGBOSS_OPTIONS, PGBOSS_TOKEN } from "./utils/consts";
16
16
  import {
17
17
  PgBossModuleAsyncOptions,
18
18
  PgBossOptionsFactory,
19
+ PgBossModuleOptions,
19
20
  } from "./interfaces/pgboss-module-options.interface";
20
21
  import { HandlerScannerService } from "./handler-scanner.service";
21
- import { handleRetry } from "utils/handleRetry";
22
+ import { handleRetry } from "./utils/handleRetry";
22
23
 
23
24
  @Global()
24
25
  @Module({
@@ -43,18 +44,10 @@ export class PgBossModule
43
44
 
44
45
  const pgBossProvider = {
45
46
  provide: PGBOSS_TOKEN,
46
- useFactory: async (pgBossOptions) => {
47
+ useFactory: async (pgBossOptions: PgBossModuleOptions) => {
47
48
  const boss = await lastValueFrom(
48
- defer(() =>
49
- new PgBoss({
50
- connectionString: pgBossOptions.connectionString,
51
- }).start(),
52
- ).pipe(
53
- handleRetry(
54
- pgBossOptions.retryAttempts,
55
- pgBossOptions.retryDelay,
56
- pgBossOptions.verboseRetryLog,
57
- ),
49
+ defer(() => new PgBoss(pgBossOptions).start()).pipe(
50
+ handleRetry(pgBossOptions.retryLimit, pgBossOptions.retryDelay),
58
51
  ),
59
52
  );
60
53
  boss.on("error", (error: Error) => {
@@ -1,5 +1,11 @@
1
1
  import { Injectable } from "@nestjs/common";
2
- import PgBoss, { WorkWithMetadataHandler } from "pg-boss";
2
+ import {
3
+ WorkWithMetadataHandler,
4
+ PgBoss,
5
+ SendOptions,
6
+ ScheduleOptions,
7
+ WorkOptions,
8
+ } from "pg-boss";
3
9
  import { Inject } from "@nestjs/common";
4
10
  import { PGBOSS_TOKEN } from "./utils/consts";
5
11
  import { transformOptions } from "./utils/helpers";
@@ -19,7 +25,7 @@ export class PgBossService {
19
25
  async scheduleJob<TData extends object>(
20
26
  name: string,
21
27
  data: TData,
22
- options?: PgBoss.SendOptions,
28
+ options?: SendOptions,
23
29
  ) {
24
30
  await this.pgBoss.createQueue(name);
25
31
  await this.pgBoss.send(name, data, options);
@@ -29,7 +35,7 @@ export class PgBossService {
29
35
  name: string,
30
36
  cron: string,
31
37
  data?: TData,
32
- options?: PgBoss.ScheduleOptions,
38
+ options?: ScheduleOptions,
33
39
  ) {
34
40
  await this.pgBoss.createQueue(name);
35
41
  await this.pgBoss.schedule(name, cron, data ?? {}, options ?? {});
@@ -40,7 +46,7 @@ export class PgBossService {
40
46
  cron: string,
41
47
  handler: WorkWithMetadataHandler<TData>,
42
48
  data?: TData,
43
- options?: PgBoss.ScheduleOptions,
49
+ options?: ScheduleOptions,
44
50
  ) {
45
51
  await this.pgBoss.createQueue(name);
46
52
  await this.pgBoss.schedule(name, cron, data ?? {}, options ?? {});
@@ -54,7 +60,7 @@ export class PgBossService {
54
60
  async registerJob<TData extends object>(
55
61
  name: string,
56
62
  handler: WorkWithMetadataHandler<TData>,
57
- options?: PgBoss.WorkOptions,
63
+ options?: WorkOptions,
58
64
  ) {
59
65
  await this.pgBoss.createQueue(name);
60
66
  await this.pgBoss.work<TData>(
@@ -1,16 +1,11 @@
1
1
  import { of, throwError } from "rxjs";
2
2
  import { mergeMap, retryWhen, delay } from "rxjs/operators";
3
- import { LOGGER } from "./consts";
4
- import { Logger } from "@nestjs/common";
5
3
 
6
4
  export function handleRetry(
7
5
  retryAttempts = 9,
8
6
  retryDelay = 3000,
9
- verbose = false,
10
7
  toRetry: (err: any) => boolean = (_err: any) => true,
11
8
  ) {
12
- const logger = new Logger(LOGGER);
13
-
14
9
  return <T>(source: import("rxjs").Observable<T>) =>
15
10
  source.pipe(
16
11
  retryWhen((attempts) =>
@@ -19,14 +14,6 @@ export function handleRetry(
19
14
  const includeError = toRetry(error);
20
15
 
21
16
  if (includeError) {
22
- if (verbose) {
23
- logger.warn(
24
- `Attempt ${index + 1}: Retrying in ${
25
- retryDelay / 1000
26
- } seconds...`,
27
- );
28
- }
29
-
30
17
  if (index + 1 >= retryAttempts) {
31
18
  return throwError(() => new Error(error.message));
32
19
  }
@@ -1,14 +1,12 @@
1
- import PgBoss from "pg-boss";
1
+ import { WorkOptions, ScheduleOptions } from "pg-boss";
2
2
 
3
- export function transformOptions(
4
- options?: PgBoss.WorkOptions | PgBoss.ScheduleOptions,
5
- ) {
3
+ export function transformOptions(options?: WorkOptions | ScheduleOptions) {
6
4
  if (!options) return {};
7
5
 
8
6
  const transformedOptions: any = { ...options };
9
7
 
10
- if (typeof options.priority === "number") {
11
- transformedOptions.priority = options.priority > 0;
8
+ if (typeof (options as any).priority === "number") {
9
+ transformedOptions.priority = (options as any).priority > 0;
12
10
  }
13
11
 
14
12
  return transformedOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavezync/nestjs-pgboss",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "A NestJS module that integrates pg-boss for job scheduling and handling.",
5
5
  "license": "MIT",
6
6
  "author": "samaratungajs@wavezync.com",
@@ -21,22 +21,22 @@
21
21
  "test:e2e": "jest --config ./test/jest-e2e.json"
22
22
  },
23
23
  "peerDependencies": {
24
- "@nestjs/common": "^9 || ^10",
25
- "@nestjs/core": "^9 || ^10",
26
- "pg-boss": "^10",
24
+ "@nestjs/common": "^11",
25
+ "@nestjs/core": "^11",
26
+ "pg-boss": "^12",
27
27
  "reflect-metadata": "^0.1.13 || ^0.2.0",
28
28
  "rxjs": "^7.2.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@nestjs/cli": "^10.0.0",
32
- "@nestjs/schematics": "^10.0.0",
33
- "@nestjs/testing": "^10.0.0",
31
+ "@nestjs/cli": "^11.0.0",
32
+ "@nestjs/schematics": "^11.0.0",
33
+ "@nestjs/testing": "^11.0.0",
34
34
  "@types/express": "^4.17.17",
35
35
  "@types/jest": "^29.5.2",
36
36
  "@types/node": "^20.3.1",
37
37
  "@types/supertest": "^6.0.0",
38
- "@typescript-eslint/eslint-plugin": "^7.0.0",
39
- "@typescript-eslint/parser": "^7.0.0",
38
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
39
+ "@typescript-eslint/parser": "^8.0.0",
40
40
  "eslint": "^8.42.0",
41
41
  "eslint-config-prettier": "^9.0.0",
42
42
  "eslint-plugin-prettier": "^5.0.0",
@@ -48,7 +48,7 @@
48
48
  "ts-loader": "^9.4.3",
49
49
  "ts-node": "^10.9.1",
50
50
  "tsconfig-paths": "^4.2.0",
51
- "typescript": "^5.1.3"
51
+ "typescript": "^5.7.0"
52
52
  },
53
53
  "jest": {
54
54
  "roots": [
@@ -1,21 +1,32 @@
1
1
  import { Test, TestingModule } from "@nestjs/testing";
2
- import PgBoss from "pg-boss";
2
+ import { PgBoss } from "pg-boss";
3
3
  import { PgBossService } from "../lib/pgboss.service";
4
4
  import { PGBOSS_TOKEN } from "../lib/utils/consts";
5
5
 
6
- describe("PgBossService", () => {
7
- let service: PgBossService;
8
- let mockPgBoss: jest.Mocked<PgBoss>;
9
-
10
- beforeEach(async () => {
11
- mockPgBoss = {
6
+ jest.mock("pg-boss", () => {
7
+ return {
8
+ PgBoss: jest.fn().mockImplementation(() => ({
9
+ on: jest.fn(),
12
10
  start: jest.fn(),
13
- work: jest.fn(),
11
+ stop: jest.fn(),
14
12
  send: jest.fn(),
15
13
  schedule: jest.fn(),
14
+ work: jest.fn(),
16
15
  createQueue: jest.fn(),
17
- getQueue: jest.fn(),
18
- } as any;
16
+ })),
17
+ };
18
+ });
19
+
20
+ describe("PgBossService", () => {
21
+ let service: PgBossService;
22
+ let mockPgBoss: any;
23
+
24
+ beforeEach(async () => {
25
+ mockPgBoss = new PgBoss("connectionString");
26
+ mockPgBoss.createQueue.mockResolvedValue(undefined);
27
+ mockPgBoss.send.mockResolvedValue("job-id");
28
+ mockPgBoss.schedule.mockResolvedValue(undefined);
29
+ mockPgBoss.work.mockResolvedValue("worker-id");
19
30
 
20
31
  const module: TestingModule = await Test.createTestingModule({
21
32
  providers: [