@wisemen/pgboss-nestjs-job
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Config

Make sure that the env variable DATABASE_URI is defined.

Usage

  1. Create an entrypoint that creates an NestJs application context instance that contains the PgBossWorkerModule.
@Module({
  imports: [
    AppModule.forRoot(),
    PgBossWorkerModule.forRoot({
      queueName, // The name of the queue to process
      concurrency, // The number of jobs to process concurrently
      batchSize, // The number of jobs to fetch
      fetchRefreshThreshold, // Refresh threshold to fetch jobs
      pollInterval // The interval (in milliseconds) to poll for new jobs
    })
  ]
})
class WorkerModule {}

class Worker extends WorkerContainer {
  async bootstrap (): Promise<INestApplicationContext> {
    return await NestFactory.createApplicationContext(WorkerModule)
  }
}

const _worker = new Worker()
  1. Create a type to define the data your job needs
export interface MyJobData extends BaseJobData {
  uuid: string
  // other data here
}
  1. Create a job definition
@PgBossJob('queue-name')
export class MyJob extends BaseJob<MyJobData> {}
  1. Create a job handler (make sure to provide it)
@Injectable()
@PgBossJobHandler(MyJob)
export class MyJobHandler extends JobHandler<MyJob> {
  public async run (data: MyJobData): Promise<void> {
    // Do stuff
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @wisemen/pgboss-nestjs-job

Weekly Downloads

334

Version

1.0.6

License

ISC

Unpacked Size

51 kB

Total Files

59

Last publish

Collaborators

  • wouter.appwise
  • kobe-kwanten-wisemen
  • jorenvandeweyer
  • robbe95
  • fullmetaljs
  • maartensijmkens
  • wisemen-sysops
  • peetha
  • daanpersoons
  • jonasvannieuwenhuijsen
  • yuhanghu
  • jonasbeckers