diff --git a/README.MD b/README.MD index 1c9ff84..c3ac069 100644 --- a/README.MD +++ b/README.MD @@ -63,6 +63,10 @@ export class JobSchedulerService { ``` +#### Access `boss` Directly + +You can access the `PgBoss` instance directly via `pgBossService.boss` + #### Handle jobs using the `@Job` decorator ```ts diff --git a/lib/pgboss.service.ts b/lib/pgboss.service.ts index ea2ba75..ac18721 100644 --- a/lib/pgboss.service.ts +++ b/lib/pgboss.service.ts @@ -5,14 +5,22 @@ import { PGBOSS_TOKEN } from "./utils/consts"; @Injectable() export class PgBossService { - constructor(@Inject(PGBOSS_TOKEN) private readonly boss: PgBoss) {} + private pgBoss: PgBoss; + + constructor(@Inject(PGBOSS_TOKEN) boss: PgBoss) { + this.pgBoss = boss; + } + + get boss(): PgBoss { + return this.pgBoss; + } async scheduleJob( name: string, data: TData, options?: PgBoss.SendOptions, ) { - await this.boss.send(name, data, options); + await this.pgBoss.send(name, data, options); } async scheduleCronJob( @@ -21,7 +29,7 @@ export class PgBossService { data?: TData, options?: PgBoss.ScheduleOptions, ) { - await this.boss.schedule(name, cron, data ?? {}, options ?? {}); + await this.pgBoss.schedule(name, cron, data ?? {}, options ?? {}); } async registerCronJob( @@ -31,8 +39,8 @@ export class PgBossService { data?: TData, options?: PgBoss.ScheduleOptions, ) { - await this.boss.schedule(name, cron, data ?? {}, options ?? {}); - await this.boss.work( + await this.pgBoss.schedule(name, cron, data ?? {}, options ?? {}); + await this.pgBoss.work( name, { ...options, includeMetadata: true }, handler, @@ -44,7 +52,7 @@ export class PgBossService { handler: WorkWithMetadataHandler, options?: PgBoss.BatchWorkOptions, ) { - await this.boss.work( + await this.pgBoss.work( name, { ...options, includeMetadata: true }, handler,