queued-jobs

A library to handle jobs in a smooth way with help of queue for nodejs and browser.


License
MIT
Install
npm install queued-jobs@1.1.0

Documentation

queued-jobs

A library to handle jobs in a smooth way with help of queue for nodejs and browser

Dependency Status devDependency Status Build Status: Linux Build Status: Windows npm version Downloads gzip size

scene

It should be one queue, multiple workers.

All workers will try to fetch one job data from the queue, if one worker fails to fetch one, it will stop; otherwise it will handle the job.

A worker will wait asynchronously, until the job is success, or error, or timeout, then it will try to fetch one another job data from the queue, just like before.

if queue's length > maxQueueLength, the front item will be removed and errored immidiately, until queue's length <= maxQueueLength

install

yarn add queued-jobs

usage

import QueuedJobs from "queued-jobs";
// <script src="./node_modules/queued-jobs/queued-jobs.min.js"></script>

// only one queue
const queuedJobs = new QueuedJobs()

// multiple workers
for (let i = 0; i < 2; i++) {
    queuedJobs.registerHandler(async (data) => {
        // do heavy work
        return 'abc'
    })
}

// a new job
const data = 123
const result = await queuedJobs.handle(data)

options

const queuedJobs = new QueuedJobs(50 /* max queue length */, 30000 /* timeout */, 100 /* max listeners */)