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

@absolutejs/queue

v0.3.0

Published

A durable, typed job queue for Elysia and the AbsoluteJS ecosystem

Downloads

1,482

Readme

@absolutejs/queue

A durable, typed background-job queue for Elysia and the AbsoluteJS ecosystem. Persists jobs, claims them safely across workers, retries with backoff, dead-letters, and runs delayed one-shots.

It does not reinvent cron — pair it with @elysiajs/cron for recurring triggers. Cron decides when; the queue guarantees the work happens (once, surviving restarts).

Status: early (0.0.4). In-memory store, schema-defined typed registry, worker, Elysia plugin, admin routes, standalone worker runner, and a runHandlerOnce helper for manual triggers / tests. Production store: @absolutejs/queue-postgres.

Install

bun add @absolutejs/queue elysia

Usage

import { Elysia } from 'elysia';
import {
	createInMemoryJobStore,
	createJobRegistry,
	defineJobs,
	queue,
	t
} from '@absolutejs/queue';

// Define jobs once: kind -> payload schema. Payload types are inferred from this
// (no hand-written job map, no generics) and validated at enqueue + dequeue.
// Build schemas with `t` from this package so they share one TypeBox instance.
const jobs = defineJobs({
	'email.send': t.Object({ to: t.String(), subject: t.String() }),
	'webhook.deliver': t.Object({ url: t.String(), body: t.Unknown() })
});

const store = createInMemoryJobStore(jobs);
const registry = createJobRegistry(jobs)
	.on('email.send', async ({ to, subject }) => {
		// to: string, subject: string — inferred from the schema
	})
	.on('webhook.deliver', async ({ url, body }, { attempts }) => {
		// retried automatically; `attempts` is which try this is
	});

const app = new Elysia()
	.use(queue({ registry, store })) // in-process worker auto-starts
	.post('/welcome/:email', ({ params, queue }) =>
		queue.enqueue('email.send', {
			subject: 'Welcome',
			to: params.email
		})
	)
	.post('/notify', ({ body, queue }) =>
		// delayed one-shot: deliver the webhook in 1 hour
		queue.enqueue(
			'webhook.deliver',
			{ body, url: 'https://example.com/hook' },
			{ runAt: Date.now() + 60 * 60 * 1000 }
		)
	)
	.listen(3000);

Recurring jobs (with @elysiajs/cron)

Pattern: keep the store at module scope so both the queue plugin's worker and the cron triggers reference the same backing state. The cron run callback doesn't receive an Elysia Context, so it can't reach the queue via decorators — it closes over the imported store directly.

// src/jobs/index.ts
import {
	createInMemoryJobStore,
	createJobRegistry,
	defineJobs,
	queue,
	t
} from '@absolutejs/queue';
import { cron } from '@elysiajs/cron';
import { Elysia } from 'elysia';

const jobs = defineJobs({
	'email.send': t.Object({ to: t.String(), subject: t.String() })
});

// Module-scoped so cron + worker reference the same backing state.
export const store = createInMemoryJobStore(jobs);
export const registry = createJobRegistry(jobs).on(
	'email.send',
	async () => {}
);

export const backgroundJobs = new Elysia({ name: 'background-jobs' })
	.use(queue({ registry, store }))
	.use(
		cron({
			name: 'weekly-digest',
			pattern: '0 8 * * 1', // Mondays at 08:00
			run: () =>
				store.enqueue({
					idempotencyKey: `weekly-digest:${new Date().toISOString().slice(0, 10)}`,
					kind: 'email.send',
					payload: {
						subject: 'Weekly digest',
						to: '[email protected]'
					}
				})
		})
	);

Tag enqueues with a per-day idempotencyKey so a misfire doesn't double-run.

One-shot manual triggers (runHandlerOnce)

Sometimes you want to invoke a handler directly — manual backfills, admin re-runs, unit tests, or bun scripts/foo.ts wrappers that share logic with the cron. Use runHandlerOnce: it validates the payload through the registry's schema and synthesises a JobContext for you, then runs the handler — no worker, no store writes.

// scripts/runWeeklyDigest.ts
import { runHandlerOnce } from '@absolutejs/queue';
import { registry } from '../src/jobs/registry'; // direct import — see warning below

await runHandlerOnce(registry, 'email.send', {
	to: '[email protected]',
	subject: 'Weekly digest (manual trigger)'
});

Don't import the barrel that re-exports backgroundJobs. Importing the Elysia plugin pulls in @elysiajs/cron, which keeps timers alive and prevents your script from exiting. Either (a) split your jobs module so the registry is exported from a different file than backgroundJobs, or (b) process.exit(0) at the end of your script.

runHandlerOnce accepts an options.context override (for attempts, maxAttempts, id, etc.) and an options.validators override (false to skip validation, or a pre-compiled JobValidators for hot loops).

How it works

  • Schema-defined jobsdefineJobs is the single source of truth: payload types are inferred from TypeBox schemas (no hand-written job map, no <Jobs> generics), and payloads are validated at enqueue and dequeue.
  • Typed registrykind → payload → handler, checked end to end.
  • JobStore interfaceenqueue, claimDue (atomic), complete, fail, reapStuck, listByKind. Swap createInMemoryJobStore for a durable adapter in prod.
  • Worker — claims due jobs up to a concurrency cap, runs handlers, retries with exponential backoff, dead-letters after maxAttempts, and reaps jobs whose worker died (lease + reapStuck).
  • Idempotency — pass idempotencyKey to enqueue to dedupe.

License

CC BY-NC 4.0