A lightweight message queue system built on Redis, supporting cron jobs and one-off tasks.
npm install @leotermine/redismq
import { QueueManager } from "@leotermine/redismq"; import { Redis } from "ioredis"; // 1. Configure Redis const redisConfig = { port: 6379, host: 'localhost', // or the host in use username: '', password: '', maxRetriesPerRequest: null, enableReadyCheck: false, }; // 2. Initialize Redis client const client = new Redis(redisConfig); // 3. Initialize Queue Manager const contextApp = {}; // Optional context passed to job handlers const app = QueueManager.init(client, contextApp, 1); // Last param is concurrency // 4. Define a job const myJob = { path: 'category/job-name', // Must follow 'category/name' format run: (ctx, job) => { console.log('Job running!', job); }, options: { repeat: { pattern: '* * * * *' // Cron pattern (optional) }, attempts: 3 // Retry attempts (optional) } }; // 5. Register job app.registerJob(myJob); // 6. Start processing app.processJobs(); // 7. Add one-off job (optional) app.addJob('category/job-name', { data: 'your-data' }, { attempts: 3 });
const cronJob = { path: 'crons/hello-world', run: (ctx, job) => { console.log("Running on schedule"); }, options: { repeat: { pattern: "* * * * *" // Runs every minute } } };
const oneOffJob = { path: 'tasks/send-email', run: (ctx, job) => { console.log("Running once"); } };
init(redisClient, context, concurrency)
: Initialize queue managerregisterJob(job)
: Register a new job typeaddJob(path, data, options)
: Add a job instanceprocessJobs()
: Start processing jobsgetAllJobs()
: Get all jobs in queuesinterface JobOptions { repeat?: { pattern: string; // Cron pattern }; attempts?: number; // Retry attempts _id?: string; // Custom job ID priority?: number; // Job priority delayUntil?: Date; // Delay execution }
MIT
Add Package
deno add jsr:@leotermine/redismq
Import symbol
import * as redismq from "@leotermine/redismq";
---- OR ----
Import directly with a jsr specifier
import * as redismq from "jsr:@leotermine/redismq";
Add Package
npx jsr add @leotermine/redismq
Import symbol
import * as redismq from "@leotermine/redismq";
Add Package
yarn dlx jsr add @leotermine/redismq
Import symbol
import * as redismq from "@leotermine/redismq";
Add Package
pnpm dlx jsr add @leotermine/redismq
Import symbol
import * as redismq from "@leotermine/redismq";
Add Package
bunx jsr add @leotermine/redismq
Import symbol
import * as redismq from "@leotermine/redismq";