Registry / devops / lib-job-queue

lib-job-queue

JSON →
library2.1.0jsnpmunverified

A simple Node.js library for creating sequential job queues where each task is a child process. Version 2.1.0 is the latest stable release, with infrequent updates. It differentiates from other job queue libraries by focusing solely on child process execution in strict sequence, with built-in events (task, exit, end) and an abort mechanism that kills the current process (default SIGKILL).

npm install lib-job-queue
INSTALL
IMPORT
SIG · LIB-JOB-QUEUE
L
lib-job-queue
devopsjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (factory function)
var Job = require('lib-job-queue')();
var jobQueue = require('lib-job-queue'); jobQueue();
The module exports a factory function that must be called with parentheses to get a Job constructor.
Job.New()
var job = Job.New();
var job = new Job();
Use Job.New() method to create a new job instance, not the new keyword.
job.add()
job.add({ exec: 'ps', args: ['aux'], envs: process.env });
job.add('ps', ['aux']);
add() expects an object with exec, args, envs properties; positional arguments are not supported.
job.emitter
job.emitter.on('task', callback);
job.on('task', callback);
Events are emitted on the emitter property, not directly on the job object.
job.abort()
job.abort();
job.abort('SIGTERM'); // valid but less common
abort() kills the current child process with SIGKILL by default; you can pass a custom signal.

Creates a sequential job queue, adds a single echo task, and listens for exit and end events.

var Job = require('lib-job-queue')(); var job = Job.New(); job.add({ exec: 'echo', args: ['Hello from job queue'], envs: process.env }); job.emitter.on('exit', function (status) { console.log('Process exited with code:', status.code); }); job.emitter.on('end', function () { console.log('All tasks completed'); });
Debug
Known issues
gotchaThe default kill signal for abort() is SIGKILL, which cannot be caught by the child process. This means the child process will be terminated immediately without cleanup.
fix
If you need graceful shutdown, pass a different signal like 'SIGTERM' to abort().
affects: >=0.0.0
gotchaAdding a job after an 'end' event triggers another 'end' event when that new job completes. This can cause unexpected event listener callbacks.
fix
Be careful about adding tasks after the queue has ended; consider resetting or managing state accordingly.
affects: >=0.0.0
gotchaThe require function must be called immediately: var Job = require('lib-job-queue')(). Forgetting the initial call returns a function instead of a Job constructor.
fix
Always include the parentheses: require('lib-job-queue')().
affects: >=0.0.0
gotchajob.current is only available while a task is running; accessing it after the task completes returns undefined.
fix
Access job.current within a 'task' event handler or when you know a process is active.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Job is not a constructor
Calling require('lib-job-queue') without the additional invocation parentheses, then using new Job().
fix
Change to require('lib-job-queue')() to get the constructor function.
TypeError: job.emitter is undefined
Trying to access job.emitter before creating a job with Job.New().
fix
Ensure you have created a job instance: var job = Job.New(); before using job.emitter.
Error: exec must be a string
Passing an object to job.add() without the exec property or with a non-string value.
fix
Provide an object with exec, args, envs: job.add({ exec: 'ls', args: ['-la'], envs: process.env });
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
lib-job-queue — npm install lib-job-queue · libregistry