
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@anephenix/job-queue
Advanced tools
A Node.js Job Queue library using Redis.
npm i @anephenix/job-queue
You will need a create a Redis client, and make it accessible to the queue files, perhaps in a redis.ts file:
// Dependencies
import { createClient, type RedisClientType } from "redis";
import config from "./config.ts";
const redis: RedisClientType = createClient(config.redis);
await redis.connect();
export default redis;
Once you have that, you can create a queue like this:
import redis from './redis.ts';
import type { RedisClientType } from 'redis';
import { Queue, type Hooks } from '@anephenix/job-queue';
type QueueOptions = { queueKey: string; redis: RedisClientType, hooks: Partial<Hooks> };
const queueOptions:QueueOptions = { queueKey: 'messages', redis, hooks: {} };
const messageQueue = new Queue(queueOptions);
export default messageQueue;
Once you have the queue ready, you can add jobs like this:
const job = {
name: 'job-001',
data: {
from: 'bob@bob.com',
to: 'sally@sally.com',
subject: 'Have you got the document for ML results?',
body: 'I want to check what the loss rate was. Thanks.',
},
};
await messageQeueue.add({ name: 'message', data });
Workers can be setup like this:
import { type Job, Worker } from '@anephenix/job-queue';
import messageQueue from '../queues/messageQueue.ts';
type MessageJob = Job & {
data: {
id: string;
to: string;
from: string;
content: string;
created_at: string;
}
};
class MessageWorker extends Worker {
async processJob(job:Job): Promise<void> {
this.status = 'processing';
try {
/* Do something with the job's data */
const { id, from, to, content } = job.data;
await this.completeJob(job);
} catch (err) {
console.error('Error processing job:', err);
await this.failJob(job);
}
return;
}
}
const messageWorker = new MessageWorker(messageQueue);
export default messageWorker;
Workers are the base class on which to create Workers tailored to processing the job. In the example above, we have an EmailWorker whose processJob function is customised to send an email via the 'sendEmail' function. The worker is now setup to start processing jobs.
await emailWorker.start();
The worker will now poll the queue for available jobs. Once it has one, it will take the job and process it.
await emailWorker.stop();
Hooks are a way to trigger functions before and after these actions are called on the queue:
This gives you the ability to do things like collect data on how many jobs are being added to a queue, how quickly they are being processed, and so on.
There are 2 types of hook, pre and post. A pre hook is called before the action is triggered, and a post hook is called after.
The way to setup hooks to call can be demonstrated in the example below:
const queueKey = 'email';
const queue = new Queue({
queueKey,
redis,
hooks: {
add: {
pre: async (job) => {
// Do something with the job before it is added
return job;
},
post: async (job) => {
// Do something with the job after it is added
return job;
},
},
take: {},
complete: {},
fail: {},
},
});
©2025 Anephenix Ltd. Job Queue is licensed under the MIT license.
FAQs
Job Queue
We found that @anephenix/job-queue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.