From 0c9badf2166351fcba579a8ca098d1a6a63d4bd3 Mon Sep 17 00:00:00 2001 From: samaratungajs Date: Sun, 8 Sep 2024 21:48:30 +0530 Subject: [PATCH 1/2] feat: direct access to pgboss added --- README.MD | 4 ++++ lib/pgboss.service.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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..a77c1d5 100644 --- a/lib/pgboss.service.ts +++ b/lib/pgboss.service.ts @@ -5,7 +5,10 @@ import { PGBOSS_TOKEN } from "./utils/consts"; @Injectable() export class PgBossService { - constructor(@Inject(PGBOSS_TOKEN) private readonly boss: PgBoss) {} + public boss: PgBoss; + constructor(@Inject(PGBOSS_TOKEN) boss: PgBoss) { + this.boss = boss; + } async scheduleJob( name: string, From 6ebd1400edd48b75106dad4aa317e4f8236588d6 Mon Sep 17 00:00:00 2001 From: samaratungajs Date: Sun, 8 Sep 2024 23:14:02 +0530 Subject: [PATCH 2/2] fix: getter for boss instance added --- lib/pgboss.service.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/pgboss.service.ts b/lib/pgboss.service.ts index a77c1d5..ac18721 100644 --- a/lib/pgboss.service.ts +++ b/lib/pgboss.service.ts @@ -5,9 +5,14 @@ import { PGBOSS_TOKEN } from "./utils/consts"; @Injectable() export class PgBossService { - public boss: PgBoss; + private pgBoss: PgBoss; + constructor(@Inject(PGBOSS_TOKEN) boss: PgBoss) { - this.boss = boss; + this.pgBoss = boss; + } + + get boss(): PgBoss { + return this.pgBoss; } async scheduleJob( @@ -15,7 +20,7 @@ export class PgBossService { data: TData, options?: PgBoss.SendOptions, ) { - await this.boss.send(name, data, options); + await this.pgBoss.send(name, data, options); } async scheduleCronJob( @@ -24,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( @@ -34,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, @@ -47,7 +52,7 @@ export class PgBossService { handler: WorkWithMetadataHandler, options?: PgBoss.BatchWorkOptions, ) { - await this.boss.work( + await this.pgBoss.work( name, { ...options, includeMetadata: true }, handler,