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

@roostjs/queue

v0.2.0

Published

Background job processing on Cloudflare Queues. Define jobs as classes, dispatch them with one line, and configure retry behavior with decorators.

Readme

@roostjs/queue

Background job processing on Cloudflare Queues. Define jobs as classes, dispatch them with one line, and configure retry behavior with decorators.

Part of Roost — the Laravel of Cloudflare Workers.

Installation

bun add @roostjs/queue

Quick Start

import { Job, Queue, MaxRetries, Backoff } from '@roostjs/queue';

@Queue('emails')
@MaxRetries(5)
@Backoff('exponential')
class SendWelcomeEmail extends Job<{ userId: string; email: string }> {
  async handle() {
    await sendEmail(this.payload.email, 'Welcome!');
  }

  onFailure(error: Error) {
    console.error('Failed to send welcome email:', error.message);
  }
}

// Dispatch from anywhere
await SendWelcomeEmail.dispatch({ userId: '123', email: '[email protected]' });

// Dispatch with a delay
await SendWelcomeEmail.dispatchAfter(60, { userId: '123', email: '[email protected]' });

Features

  • Job base class with typed payload and attempt
  • dispatch() and dispatchAfter(seconds) static methods
  • chain() for sequential job pipelines
  • batch() to dispatch a group of jobs with a shared batch ID
  • Configurable per-job retry behavior: @MaxRetries, @RetryAfter, @Backoff('fixed' | 'exponential')
  • @Queue(name) routes jobs to specific CF Queue bindings
  • @Delay(seconds) sets a default dispatch delay
  • @JobTimeout(seconds) documents expected max duration
  • onSuccess() and onFailure() optional hooks per job
  • JobConsumer handles CF Queue message batches, including retry with calculated backoff
  • Job.fake() / Job.assertDispatched() for zero-infrastructure testing

API

Job decorators

@Queue('my-queue')        // which CF Queue binding to send to (default: 'default')
@MaxRetries(3)            // max attempts before ack-ing a failed message (default: 3)
@RetryAfter(60)           // base retry delay in seconds (default: 60)
@Backoff('exponential')   // 'fixed' | 'exponential' (default: 'fixed')
@Delay(30)                // default dispatch delay in seconds (default: 0)
@JobTimeout(120)          // informational timeout hint in seconds
class MyJob extends Job<MyPayload> {
  async handle() { /* ... */ }
}

Dispatching

// Immediate
await MyJob.dispatch(payload)

// Delayed
await MyJob.dispatchAfter(seconds, payload)

// Sequential chain — each job runs after the previous succeeds
await Job.chain([
  { jobClass: FetchData, payload: { url } },
  { jobClass: ProcessData, payload: {} },
  { jobClass: NotifyUser, payload: { userId } },
])

// Batch — all dispatched at once, grouped by a shared batchId
const batchId = await Job.batch([
  { jobClass: SendEmail, payload: { to: '[email protected]' } },
  { jobClass: SendEmail, payload: { to: '[email protected]' } },
])

Consumer (wrangler.toml queue handler)

import { JobConsumer, JobRegistry } from '@roostjs/queue';

const registry = new JobRegistry();
registry.register(SendWelcomeEmail);
registry.register(ProcessData);

const consumer = new JobConsumer(registry);

// In your CF Worker queue handler:
export default {
  async queue(batch: MessageBatch, env: Env) {
    await consumer.processBatch(batch.messages);
  }
}

Testing

SendWelcomeEmail.fake();

await someServiceThatDispatchesEmail();

SendWelcomeEmail.assertDispatched();             // at least one dispatched
SendWelcomeEmail.assertDispatched('SendWelcomeEmail');  // by name
SendWelcomeEmail.assertNotDispatched();          // none dispatched

SendWelcomeEmail.restore();

Documentation

Full documentation at roost.birdcar.dev/docs/reference/queue

License

MIT