Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: direct access to pgboss instance #12

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions lib/pgboss.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData extends object>(
name: string,
data: TData,
options?: PgBoss.SendOptions,
) {
await this.boss.send(name, data, options);
await this.pgBoss.send(name, data, options);
}

async scheduleCronJob<TData extends object>(
Expand All @@ -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<TData extends object>(
Expand All @@ -31,8 +39,8 @@ export class PgBossService {
data?: TData,
options?: PgBoss.ScheduleOptions,
) {
await this.boss.schedule(name, cron, data ?? {}, options ?? {});
await this.boss.work<TData>(
await this.pgBoss.schedule(name, cron, data ?? {}, options ?? {});
await this.pgBoss.work<TData>(
name,
{ ...options, includeMetadata: true },
handler,
Expand All @@ -44,7 +52,7 @@ export class PgBossService {
handler: WorkWithMetadataHandler<TData>,
options?: PgBoss.BatchWorkOptions,
) {
await this.boss.work<TData>(
await this.pgBoss.work<TData>(
name,
{ ...options, includeMetadata: true },
handler,
Expand Down