npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wisemen/pgboss-nestjs-job

v2.1.1

Published

Make sure that the env variable `DATABASE_URI` is defined.

Readme

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
      bouncerModule  // An optional bouncer which will prevent jobs from being fetched
    })
  ]
})
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
  }
}

QueueBouncer

Some workers / queues only need to run when some external service is online. The QueueBouncer base class is used by workers to determine wether they should poll for jobs or not by calling the canProceed method on the bouncer. This method typically performs the health check on an external service.

The queuebouncer is provided to the worker by creating and exportin a provider for the QueueBouncer class. An example module can be:

@Module({
  imports: [CuoptClientModule],
  providers: [{
    provide: QueueBouncer,
    useClass: CuoptWorkerBouncer
  }],
  exports: [QueueBouncer]
})
export class CuoptWorkerBouncerModule {}

When no bouncer is set, the package will default to AllowBouncer which never blocks a worker / queue from polling for jobs.

An example of a bouncer for an external cuopt system.

@Injectable()
export class CuoptWorkerBouncer extends QueueBouncer {
  private isCuoptRunning: boolean
  private lastPolledAt: Date
  private pollPromise: Promise<boolean> | undefined

  constructor (
    private cuopt: CuoptClient
  ) {
    super()
  }

  async canProceed (): Promise<boolean> {
    if (dayjs().diff(this.lastPolledAt, 'seconds') > 2) {
      await this.pollCuopt()
    }

    return this.isCuoptRunning
  }

  private async pollCuopt () {
    if (this.pollPromise !== undefined) {
      await this.pollPromise
      return
    }

    this.pollPromise = this.cuopt.isReady()

    try {
      this.isCuoptRunning = await this.pollPromise
    } catch {
      this.isCuoptRunning = false
    } finally {
      this.lastPolledAt = new Date()
    }
  }
}