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

simple-batch-system

v2.1.0

Published

simple batch system provides job schduler like async function queueing system.

Downloads

165

Readme

npm version Known Vulnerabilities Test Coverage Maintainability

Simple Batch System (SBS)

Simple Batch System is a lightweight job scheduler library for Node.js, inspired by traditional job schedulers like PBS and SLURM. It allows you to execute asynchronous tasks with control over concurrency, retry logic, and job queuing.

Features

  • Job Queuing: Submit jobs to a queue for execution.
  • Concurrency Control: Limit the number of jobs that run in parallel.
  • Job Cancellation: Cancel jobs before they start.
  • Promise-based API: Modern and easy-to-use asynchronous API.
  • Retry Logic: Automatically retry failed jobs.
  • Event-driven: Emits events for job lifecycle (submitted, run, finished, failed).

Installation

Install the package using npm:

npm install simple-batch-system

Usage

Here’s a basic example of how to use the Simple Batch System:

import SBS from 'simple-batch-system';

// Create a new SBS instance
const sbs = new SBS({ maxConcurrent: 2 });

// Define a function to be executed as a job
const myJob = async (arg) => {
  console.log(`Job started with argument: ${arg}`);
  // Simulate an async operation
  await new Promise(resolve => setTimeout(resolve, 1000));
  console.log(`Job with argument ${arg} finished.`);
  return `Result from ${arg}`;
};

// Submit jobs to the queue
const id1 = sbs.qsub({ exec: () => myJob('A') });
const id2 = sbs.qsub({ exec: () => myJob('B') });
const id3 = sbs.qsub({ exec: () => myJob('C') });

console.log(`Submitted jobs with IDs: ${id1}, ${id2}, ${id3}`);

// You can wait for a specific job to complete
sbs.qwait(id1).then((result) => {
  console.log(`Job ${id1} completed with result: ${result}`);
});

// Or wait for all jobs to complete
sbs.qwaitAll([id1, id2, id3]).then((results) => {
  console.log('All jobs completed:', results);
});

Using a Default Executor

You can define a default executor for all jobs:

import SBS from 'simple-batch-system';

const sbs = new SBS({
  exec: async (arg) => {
    console.log(`Processing: ${arg}`);
    await new Promise(resolve => setTimeout(resolve, 500));
    return `Processed: ${arg}`;
  }
});

sbs.qsub('task1');
sbs.qsub('task2');

API Guide

new SBS(options)

Creates a new SBS instance.

  • options (Object): Configuration for the instance.
    • maxConcurrent (number): Maximum number of parallel jobs. Default: 1.
    • exec (Function): A default function to execute for jobs.
    • retry (boolean|Function): Whether to retry failed jobs. Can be a function that returns true or false.
    • maxRetry (number): The maximum number of retries.
    • retryDelay (number): The delay in milliseconds before a retry.
    • interval (number): The interval in milliseconds between starting jobs.
    • name (string): A name for the SBS instance, used for debugging.

sbs.qsub(job, [urgent])

Submits a job to the queue.

  • job (Object|Function): The job to execute. Can be a function or an object with an exec property.
  • urgent (boolean): If true, the job is added to the front of the queue.
  • Returns a unique job id.

The job object can have the following properties:

  • exec (Function): The function to execute for this job.
  • args (any): Arguments to be passed to the default executer.
  • name (string): A human-readable name for the job.
  • retry (boolean|Function): Job-specific retry logic.
  • maxRetry (number): Job-specific maximum number of retries.
  • retryDelay (number): Job-specific delay before retrying.
  • retryLater (boolean): If true, the job is pushed to the back of the queue on retry.
  • forceRetry (boolean): If true, the job will be retried even if maxRetry is exceeded.

sbs.qdel(id)

Removes a job from the queue.

  • id (string): The ID of the job to remove.
  • Returns true if the job was removed, false otherwise.

sbs.qstat(id)

Gets the status of a job.

  • id (string): The ID of the job.
  • Returns one of: "running", "waiting", "finished", "failed", "removed".

sbs.qwait(id)

Waits for a single job to complete.

  • id (string): The ID of the job.
  • Returns a Promise that resolves with the job's result or rejects with an error.

sbs.qwaitAll(ids)

Waits for multiple jobs to complete.

  • ids (string[]): An array of job IDs.
  • Returns a Promise that resolves with an array of results.

sbs.qsubAndWait(job)

Submits a job and waits for it to complete.

  • job (Object|Function): The job to execute.
  • Returns a Promise that resolves with the job's result.

Other Methods

  • start(): Starts the job queue if it was stopped.
  • stop(): Stops the job queue from starting new jobs.
  • clear(): Stops the queue and removes all waiting jobs.
  • size(): Returns the number of jobs in the queue.
  • getRunning(): Returns an array of running job IDs.
  • clearResults(): Clears stored results of finished/failed jobs to save memory.