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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@maroonedsoftware/jobbroker

v1.0.0

Published

A flexible background job processing library with support for scheduled and on-demand jobs.

Readme

@maroonedsoftware/jobbroker

A flexible background job processing library with support for scheduled and on-demand jobs. Currently ships with a pg-boss implementation for PostgreSQL-backed job queues.

Features

  • Abstract interfaces for easy testing and alternative implementations
  • Dependency injection support via injectkit
  • Scheduled jobs using cron expressions
  • On-demand jobs for immediate execution
  • PostgreSQL backing for reliability and transactional guarantees

Installation

pnpm add @maroonedsoftware/jobbroker injectkit pg-boss reflect-metadata

Note: InjectKit requires reflect-metadata to be imported at your application entry point and TypeScript configured with experimentalDecorators: true and emitDecoratorMetadata: true.

Quick Start

1. Define a Job

Create a job by extending the Job base class:

import { Injectable } from 'injectkit';
import { Job } from '@maroonedsoftware/jobbroker';

interface EmailPayload {
  to: string;
  subject: string;
  body: string;
}

@Injectable()
export class SendEmailJob extends Job<EmailPayload> {
  constructor(private readonly emailService: EmailService) {
    super();
  }

  async run(payload: EmailPayload): Promise<void> {
    await this.emailService.send(payload.to, payload.subject, payload.body);
  }
}

2. Register Jobs

Create a registry and register your jobs:

import { PgBossJobRegistryMap } from '@maroonedsoftware/jobbroker';

const registry = new PgBossJobRegistryMap();

// On-demand job (triggered manually)
registry.set('send-email', SendEmailJob);

// Scheduled job (runs on a cron schedule)
registry.set('daily-report', {
  job: DailyReportJob,
  cron: '0 9 * * *', // Every day at 9 AM
});

3. Set Up the Broker and Runner

import 'reflect-metadata';
import { PgBoss } from 'pg-boss';
import { InjectKitRegistry } from 'injectkit';
import { PgBossJobBroker, PgBossJobRunner, PgBossJobRegistryMap, JobBroker, JobRunner } from '@maroonedsoftware/jobbroker';

// Initialize pg-boss
const pgboss = new PgBoss('postgres://user:pass@localhost/mydb');
await pgboss.start();

// Set up dependency injection registry
const diRegistry = new InjectKitRegistry();

diRegistry.register(PgBossJobRegistryMap).useInstance(registry);
diRegistry.register(PgBoss).useInstance(pgboss);
diRegistry.register(JobBroker).useClass(PgBossJobBroker).asSingleton();
diRegistry.register(JobRunner).useClass(PgBossJobRunner).asSingleton();

// Build the container
const container = diRegistry.build();

// Start the job runner
const runner = container.get(JobRunner);
await runner.start();

4. Send Jobs

Use the broker to queue jobs for processing:

const broker = container.get(JobBroker);

// Send an immediate job
await broker.send('send-email', {
  to: '[email protected]',
  subject: 'Welcome!',
  body: 'Thanks for signing up.',
});

// Schedule a recurring job programmatically
await broker.schedule('cleanup', '0 0 * * *', { olderThan: 30 });

// Remove a schedule
await broker.unschedule('cleanup');

API Reference

Job<Payload>

Abstract base class for job handlers.

| Method | Description | | -------------------------------------- | -------------------------------------- | | run(payload: Payload): Promise<void> | Execute the job with the given payload |

JobBroker

Abstract interface for sending jobs to the queue.

| Method | Description | | --------------------------------------------------------------------- | ------------------------------------ | | send<P>(name: string, payload: P): Promise<void> | Queue a job for immediate processing | | schedule<P>(name: string, cron: string, payload?: P): Promise<void> | Create a recurring job schedule | | unschedule(name: string): Promise<void> | Remove a recurring job schedule |

JobRunner

Abstract interface for processing jobs from the queue.

| Method | Description | | ------------------------ | -------------------------- | | start(): Promise<void> | Start processing jobs | | stop(): Promise<void> | Gracefully stop processing |

PgBossJobRegistryMap

A Map<string, Identifier<Job> | PgBossJobRegistration> for registering jobs.

Entries can be either:

  • A job class identifier (for on-demand jobs)
  • A PgBossJobRegistration object with job and cron properties (for scheduled jobs)

Graceful Shutdown

Ensure you stop the runner during application shutdown:

process.on('SIGTERM', async () => {
  await runner.stop();
  await pgboss.stop();
  process.exit(0);
});

Peer Dependencies

  • pg-boss ^12.5.4 - PostgreSQL-based job queue
  • reflect-metadata - Required by InjectKit for decorator metadata

License

MIT