Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
decent
is a Redis-based job queue for Node.
Job queue is hard to manage, we make it decent for you.
Despite efforts from brilliant developers, a reliable job queue using node.js and redis is still somewhat of a mythical beast. And no wonder: redis isn't a queueing solution by itself and node.js isn't known for superior error handling; add concurrency into the mix and you got a leaky pipeline that's almost impossible to debug.
In short, we need better groundwork before we can harness the power of queue. Hence the birth of decent
: we want a library that provides solid building blocks for complex pipelines, so we can safely enjoy what job queue has to offer.
Promise
, works in harmony with your generator library.redis
driver, make use of native promise whenever possible, fallback to bluebird
for older Node release.npm install decent --save
Create a queue with name
and config redis client connection based on opts
, returns a decent queue instance.
var decent = require('decent');
var queue1 = decent('q1');
var queue2 = decent('q2', {
port: 6379
, host: 'localhost'
, connect_timeout: 5000
});
port
: redis server port, default to 6379
host
: redis server host, default to '127.0.0.1'
blockTimeout
: how long a client should wait for next job (see redis document on blocking command, such as BLPOP), defaults to 30
seconds, 0
to block forever.maxRetry
: how many retries a job can have before being moved to failure queue, defaults to 3
, 0
to disable retry.Create a job on queue using data
as payload and allows job specific opts
, returns a promise that resolve to the created job.
queue.add({ a: 1 }).then(function(job) {
console.log(job.data); // { a: 1 }
});
queue.add({ a: 1, b: 1 }, { retry: 1, timeout: 120 }).then(function(job) {
console.log(job.data); // { a: 1, b: 1 }
});
retry
: set initial retry counter, default to 0
timeout
: set worker timeout in seconds, default to 60
id
: job iddata
: payloadretry
: current retry count for this jobtimeout
: how many seconds a worker can run before it's terminated.Register a handler function that process jobs, and start processing jobs in queue.
queue.worker(function(job, done) {
// ... do actual work
done();
});
Must be called to signal the completion of job processing.
If called with an instance of Error
, then decent
will assume worker failed to process this job.
Fail jobs are moved back to work queue when they are below retry threshold, otherwise they are moved to failure queue.
Returns a promise that resolve to the queue length of specified queue, default to work
queue.
queue.count('work').then(function(count) {
console.log(count); // pending job count
});
queue.count('run').then(function(count) {
console.log(count); // running job count
});
queue.count('fail').then(function(count) {
console.log(count); // failed job count
});
Returns a promise that resolve to the job itself.
queue.get(1).then(function(job) {
console.log(job.id); // 1
});
Returns a promise that will resolve when job is removed from redis (both job data and job queue).
queue.remove(1).then(function() {
// ...
});
Instructs queue worker to terminate gracefully on next loop. See events on how to monitor queue.
queue.stop();
Restarts the queue worker loop. See events on how to monitor queue.
queue.restart();
decent
is an instance of EventEmitter
, so you can use queue.on('event', func)
as usual.
queue.emit('client ready')
: client is ready. (redis client has buffer built-in, so this event is emitted as soon as redis client is started.)queue.emit('client error', err)
: client connection experiences error.queue.emit('client close')
: client connection has been closed.queue.emit('client pressure', number)
: pending number of commands, useful for rate limiting.queue.emit('queue start')
: queue loop has started.queue.emit('queue ok', job)
: queue worker has processed a job
.queue.emit('queue error', err)
: queue worker has failed to processed a job and thrown err
(caught properly, so queue does not exit)queue.emit('queue exit', err)
: queue loop has terminated due to err
.queue.emit('queue stop')
: queue loop has stopped gracefully.queue.emit('add ok', job)
: job
has been added to queue.queue.emit('add error', err)
: failed to add job onto queue due to err
.npm install
npm test
Feel feel to raise any issues or feature requests, note that we do intend to keep this API simple, and all changes must be well-tested.
MIT
v0.1.5
FAQs
This is a decent Redis-based job queue for Node.
We found that decent demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.