PACKAGES

Rasengan Queue

@rasenganjs/queue adds background job queues to Rasengan Server — the Controller equivalent for async work, mirroring @rasenganjs/ws's Gateway pattern.

Installation

Terminal
npm install @rasenganjs/queue

Usage

main.ts
import { bootstrap } from '@rasenganjs/server'; import { createQueuePlugin } from '@rasenganjs/queue'; import appModule from './app.module'; bootstrap((app) => { app.registerPlugin(createQueuePlugin()); // defaults to MemoryQueueAdapter app.registerModule(appModule); // may declare queues: [EmailQueue] });
email.queue.ts
import { Queue, JobRouter, type JobHandler } from '@rasenganjs/queue'; export class EmailQueue extends Queue { name = 'emails'; jobs(router: JobRouter) { router.process('welcome', this.sendWelcome, { attempts: 3, backoff: 5_000, }); } sendWelcome: JobHandler<{ userId: string }> = async (job) => { await sendWelcomeEmail(job.data.userId); // resolve -> job completes; throw -> retried per backoff policy }; }
queue.module.ts
import { defineModule } from '@rasenganjs/server'; import { EmailQueue } from './email.queue'; export default defineModule({ queues: [EmailQueue], });

Enqueuing Jobs

Inject the queue anywhere it's exported and visible, then call .add():

Enqueuing a job
await this.emailQueue.add('welcome', { userId: user.id }); await this.emailQueue.add('reminder', { userId }, { delay: 60_000 }); // delayed await this.reportQueue.add( 'dailyDigest', {}, { repeat: { every: 86_400_000 } } ); // recurring

Scaling with Redis

The default MemoryQueueAdapter is in-process and loses jobs on restart (dev only). RedisQueueAdapter persists across restarts and is safe across multiple processes:

Redis adapter
import { createQueuePlugin, RedisQueueAdapter } from '@rasenganjs/queue'; import Redis from 'ioredis'; const client = new Redis(); app.registerPlugin( createQueuePlugin({ adapter: new RedisQueueAdapter({ client, blockingClient: client.duplicate(), }), }) );

Full Documentation

For the complete API — retry semantics, dead-letter handling, ProcessOptions, and the sweeper — see Background Queues under the Server docs.

Community

Join the Rasengan.js community to get support, ask questions, and share your projects:

Let's build something amazing with Rasengan.js! 🚀

License

This package is MIT licensed.