Skip to content
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
3 changes: 1 addition & 2 deletions lib/decorators/job.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SetMetadata } from "@nestjs/common";
import { ScheduleOptions } from "pg-boss";
import { WorkOptions } from "../interfaces/handler-metadata.interface";
import { ScheduleOptions, WorkOptions } from "pg-boss";

export const JOB_NAME = "JOB_NAME";
export const JOB_OPTIONS = "JOB_OPTIONS";
Expand Down
18 changes: 8 additions & 10 deletions lib/handler-scanner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { InstanceWrapper } from "@nestjs/core/injector/instance-wrapper";
import PgBoss from "pg-boss";
import { LOGGER } from "./utils/consts";
import { WorkOptions } from "./interfaces/handler-metadata.interface";
import { WorkOptions } from "pg-boss";

@Injectable()
export class HandlerScannerService {
Expand Down Expand Up @@ -73,15 +73,13 @@ export class HandlerScannerService {
continue;
}

const teamSize = Math.max(1, jobOptions?.teamSize ?? 1);
for (let i = 0; i < teamSize; i++) {
await this.pgBossService.registerJob(
jobName,
methodRef.bind(instance),
jobOptions,
);
}
this.logger.log(`Registered job: ${jobName} (${teamSize} worker${teamSize > 1 ? 's' : ''})`);
await this.pgBossService.registerJob(
jobName,
methodRef.bind(instance),
jobOptions,
);

this.logger.log(`Registered job: ${jobName}`);
} catch (error) {
this.logger.error(error, `Error registering job ${jobName}`);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/interfaces/handler-metadata.interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { WorkOptions as PgBossWorkOptions, ScheduleOptions } from "pg-boss";

export interface WorkOptions extends PgBossWorkOptions {
teamSize?: number;
}
import { WorkOptions, ScheduleOptions } from "pg-boss";

export interface HandlerMetadata {
jobName: string;
Expand Down
Loading