show all 78
|0.8.9||4 months ago||behrad|
|0.8.8||5 months ago||behrad|
|0.8.7||5 months ago||behrad|
|0.8.6||5 months ago||behrad|
|0.8.5||6 months ago||behrad|
|0.8.4||6 months ago||behrad|
|0.8.3||7 months ago||behrad|
|0.8.2||7 months ago||behrad|
|0.8.1||8 months ago||behrad|
|0.8.0||8 months ago||behrad|
|0.7.9||8 months ago||behrad|
|0.7.8||8 months ago||behrad|
|0.7.7||9 months ago||behrad|
|0.7.5||a year ago||behrad|
|0.7.4||a year ago||behrad|
|0.7.3||a year ago||behrad|
|0.7.2||a year ago||behrad|
|0.7.1||a year ago||behrad|
|0.7.0||a year ago||behrad|
|0.6.2||2 years ago||drudge|
|0.6.1||2 years ago||tjholowaychuk|
|0.6.0||2 years ago||tjholowaychuk|
|0.5.0||2 years ago||tjholowaychuk|
|0.4.2||2 years ago||tjholowaychuk|
|0.4.1||2 years ago||tjholowaychuk|
|0.3.4||3 years ago||tjholowaychuk|
|0.3.3||3 years ago||tjholowaychuk|
Kue is a priority job queue backed by redis, built for node.js.
PROTIP This is the latest Kue documentation, make sure to read the changelist for compatibility.
- Delayed jobs
- Distribution of parallel work load
- Job event and progress pubsub
- Rich integrated UI
- Infinite scrolling
- UI progress indication
- Job specific logging
- Powered by Redis
- Optional retries with backoff
- Full-text search capabilities
- RESTful JSON API
- Graceful workers shutdown
- Creating Jobs
- Jobs Priority
- Failure Attempts
- Failure Backoff
- Job Logs
- Job Progress
- Job Events
- Queue Events
- Delayed Jobs
- Processing Jobs
- Processing Concurrency
- Pause Processing
- Updating Progress
- Graceful Shutdown
- Redis Connection Settings
- JSON API
- Parallel Processing With Cluster
- Securing Kue
First create a job
jobs.create() with the type of job ("email"), and arbitrary job data will return a
Job, which can then be
save()ed, adding it to redis, with a default priority level of "normal". The
save() method optionally accepts a callback, responding with an
error if something goes wrong. The
title key is special-cased, and will display in the job listings within the UI, making it easier to find a specific job.
To specify the priority of a job, simply invoke the
priority() method with a number, or priority name, which is mapped to a number.
The default priority map is as follows:
By default jobs only have one attempt, that is when they fail, they are marked as a failure, and remain that way until you intervene. However, Kue allows you to specify this, which is important for jobs such as transferring an email, which upon failure, may usually retry without issue. To do this invoke the
.attempts() method with a number.
Job retry attempts are done as soon as they fail, with no delay, even if your job had a delay set via
Job#delay. If you want to delay job re-attempts upon failures (known as backoff) you can use
Job#backoff method in different ways:
In the last scenario, provided function will be called on each re-attempt to get current attempt delay value.
Job-specific logs enable you to expose information to the UI at any point in the job's life-time. To do so simply invoke
job.log(), which accepts a message string as well as variable-arguments for sprintf-like support:
Job progress is extremely useful for long-running jobs such as video conversion. To update the job's progress simply invoke
Job-specific events are fired on the
Job instances via Redis pubsub. The following events are currently supported:
For example this may look something like the following:
Note that Job level events are not guaranteed to be received upon worker process restarts, since the process will lose the reference to the specific Job object. If you want a more reliable event handler look for Queue Events.
Queue-level events provide access to the job-level events previously mentioned, however scoped to the
Queue instance to apply logic at a "global" level. An example of this is removing completed jobs:
The events available are the same as mentioned in "Job Events", however prefixed with "job ".
Delayed jobs may be scheduled to be queued for an arbitrary distance in time by invoking the
.delay(ms) method, passing the number of milliseconds relative to now. This automatically flags the
Job as "delayed".
When using delayed jobs, we must also check the delayed jobs with a timer, promoting them if the scheduled delay has been exceeded. This
setInterval is defined within
Queue#promote(ms,limit), defaulting to a check of top 200 jobs every 5 seconds.
Processing jobs is simple with Kue. First create a
Queue instance much like we do for creating jobs, providing us access to redis etc, then invoke
jobs.process() with the associated type.
Note that unlike what the name
createQueue suggests, it currently returns a singleton
Queue instance. So you can configure and use only a single
Queue object within your node.js process.
In the following example we pass the callback
done(err) to tell Kue something happened, otherwise we invoke
done() only when the job is complete. If this function responds with an error it will be displayed in the UI and the job will be marked as a failure.
Workers can pass job result as the second parameter to done
done(null,result) to store that in
result is also passed through
complete event handlers so that job producers can receive it if they like to.
By default a call to
jobs.process() will only accept one job at a time for processing. For small tasks like sending emails this is not ideal, so we may specify the maximum active jobs for this type by passing a number:
Workers can temporary pause and resume their activity. It is, after calling
pause they will receive no jobs in their process callback until
resume is called.
pause function gracefully shutdowns this worker, and uses the same internal functionality as
shutdown method in Graceful Shutdown.
For a "real" example, let's say we need to compile a PDF from numerous slides with node-canvas. Our job may consist of the following data, note that in general you should not store large data in the job it-self, it's better to store references like ids, pulling them in while processing.
We can access this same arbitrary data within a separate process while processing, via the
job.data property. In the example we render each slide one-by-one, updating the job's log and process.
As of Kue 0.7.0, a
Queue#shutdown(fn, timeout) is added which signals all workers to stop processing after their current active job is done. Workers will wait
timeout milliseconds for their active job's done to be called or mark the active job
failed with shutdown error reason. When all workers tell Kue they are stopped
fn is called.
Redis Connection Settings
By default, Kue will connect to Redis using the client default settings (port defaults to
6379, host defaults to
127.0.0.1, prefix defaults to
Queue#createQueue(options) accepts redis connection options in
prefix controls the key names used in Redis. By default, this is simply
q. Prefix generally shouldn't be changed unless you need to use one Redis instance for multiple apps. It can also be useful for providing an isolated testbed across your main application.
Connecting using Unix Domain Sockets
Since node_redis supports Unix Domain Sockets, you can also tell Kue to do so. See unix-domain-socket for your redis server configuration.
Replacing Redis Client Module
Any node.js redis client library that conforms (or when adapted) to node_redis API can be injected into Kue. You should only provide a
createClientFactory function as a redis connection factory instead of providing node_redis connection options.
Below is a sample code to enable redis-sentinel to connect to Redis Sentinel for automatic master/slave failover.
Note that all
<0.8.x client codes should be refactored to pass redis options to
Queue#createQueue instead of monkey patched style overriding of
redis#createClient or they will be broken from Kue
The UI is a small Express application, to fire it up simply run the following, altering the port etc as desired.
The title defaults to "Kue", to alter this invoke:
Note that if you are using non-default Kue options,
kue.createQueue(...) must be called before accessing
Along with the UI Kue also exposes a JSON API, which is utilized by the UI.
Query jobs, for example "GET /job/search?q=avi video":
By default kue indexes the whole Job data object for searching, but this can be customized via calling
Job#searchKeys to tell kue which keys on Job data to create index for:
You may also fully disable search indexes for redis memory optimization:
Currently responds with state counts, and worker activity time in milliseconds:
Get a job by
Get jobs with the specified range
:to, for example "/jobs/0..2", where
:order may be "asc" or "desc":
Same as above, restricting by
:state which is one of:
Same as above, however restricted to
Create a job:
Parallel Processing With Cluster
The example below shows how you may use Cluster to spread the job processing load across CPUs. Please see Cluster module's documentation for more detailed examples on using it.
.isMaster the file is being executed in context of the master process, in which case you may perform tasks that you only want once, such as starting the web app bundled with Kue. The logic in the
else block is executed per worker.
This will create an
10 * N concurrent email jobs processed in your
N core machine.
Now when you visit Kue's UI in the browser you'll see that jobs are being processed roughly
N times faster! (if you have
Through the use of app mounting you may customize the web application, enabling TLS, or adding additional middleware like Connect's
(The MIT License)
Copyright (c) 2011 LearnBoost <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.