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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jobor

v0.4.2

Published

A generic job queue library for Node.js. It helps you build reliable and scalable background job processing workflows

Downloads

6

Readme

Jobor: Advanced Job Queue Management for Node.js

Jobor is a versatile job queue management system for Node.js applications, allowing developers to schedule and process jobs efficiently. It supports both in-memory and persistent job bufstore solutions, and it offers a flexible approach to processing jobs either on the server or in worker processes.

Features

  • Flexible Processing Modes: Choose between server or worker modes to process jobs where it makes the most sense for your application.
  • Multiple Queue Adapters: Supports in-memory queues for development and BullMQ for robust, production-ready queuing.
  • Extensible Storage Options: Built-in support for in-memory bufstore, with the ability to extend to Redis for distributed, persistent job queues.
  • Process Contexts: Manage process modes dynamically within your application to optimize resource utilization.
  • Robust and Scalable: Designed to handle both small-scale applications and large, distributed systems.

Installation

npm install jobor
# or
yarn add jobor

Getting Started

import {Jobor} from 'jobor';

// Initialize Jobor with BullMQ adapter and Redis bufstore
const jobor = new Jobor({
  adapter: {name: 'bullmq'},
  bufstore: {name: 'redis'},
  processMode: 'server',
});

Create Queues

const queue = jobor.createQueue({
  name: 'send-email',
  process: async job => {
    // Replace with your email sending logic
    console.log(`Email sent to ${job.data.to}`);
  },
});

Add Jobs to the Queue

import {Job} from 'jobor';

await queue.add(
  new Job({
    name: 'send-email',
    data: {to: '[email protected]', subject: 'Welcome!'},
  }),
);
console.log('Email job added to the queue.');

Configuration

Configure Jobor to match the needs of your application:

const joborOptions = {
  adapter: {name: 'bullmq' /* BullMQ specific options */},
  bufstore: {name: 'redis' /* Redis specific options */},
  processMode: 'server', // Can be 'server' or 'worker'
};

const jobor = new Jobor(joborOptions);

Process Mode

You can manage the processing context dynamically:

import {ProcessContext} from 'jobor';

// Set the global process mode
ProcessContext.setProcessMode('worker');

// Instantiate a new context
const processContext = new ProcessContext();

console.log(processContext.isServer); // false
console.log(processContext.isWorker); // true

Server and Worker Modes

Jobor supports two processing modes:

  • Server: The server mode is designed to process jobs in the same process as the application. This is useful for small-scale applications that do not require a dedicated worker process.
  • Worker: The worker mode is designed to process jobs in a separate process from the application. This is useful for large-scale applications that require a dedicated worker process.
// Both server and worker process.
import {Jobor, Job} from 'jobor';

const jobor = new Jobor({
  adapter: {name: 'bullmq'}, // memory adapter is not supported in worker mode.
  bufstore: {name: 'redis'},
  processMode: 'server', // or 'worker' in worker process
});

const queue = jobor.createQueue({
  name: 'send-email',
  process: async job => {
    // Replace with your email sending logic
    console.log(`Email sent to ${job.data.to}`);
  },
});

// In `server` process
await queue.add(
  new Job({
    name: 'send-email',
    data: {to: '[email protected]', subject: 'Welcome!'},
  }),
);

console.log('Email job added to the queue.');

// In `worker` process
jobor.start();

Queue Adapters

Jobor supports two queue adapters currently:

  • In-Memory: A simple, in-memory queue adapter that is useful for development and testing.
  • BullMQ: A robust, production-ready queue adapter that uses Redis for persistent bufstore.

In-Memory Adapter

const {Jobor} = require('jobor');

const jobor = new Jobor({
  adapter: {
    name: 'memory',
    concurrency: 1, // Optional. Default is 1
    poolInterval: 200, // Optional. Default is 200ms
  },
});

BullMQ Adapter

const {Jobor} = require('jobor');

const jobor = new Jobor({
  adapter: {
    name: 'bullmq',
    // BullMQ specific options
  },
});

Storage

Jobor supports two bufstore options currently:

  • In-Memory: A simple, in-memory bufstore solution that is useful for development and testing.
  • Redis: A distributed, persistent bufstore solution that is useful for production applications.

In-Memory Storage

const {Jobor} = require('jobor');

const jobor = new Jobor({
  bufstore: {name: 'memory'}, // No options
});

Redis Storage

const {Jobor} = require('jobor');

const jobor = new Jobor({
  bufstore: {
    name: 'redis',
    // Redis specific options
  },
});

Advanced Usage

Jobor is built to be extended:

  • Create custom adapters by implementing the JobQueueAdapter interface.
  • Develop custom bufstore solutions with the JobBufStore interface.

Contributing

We welcome contributions of all kinds from the community! Please see the contributing guide for more information.

License

Jobor is released under the MIT License.

Support

Need help? Open an issue in our GitHub repository.

Remember to update the README with any specifics about your project, such as additional configuration options, features, or examples that can help users get started with Jobor.