Resque for Node.js (pure JS)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This respository is not under active development

Check out Rick Olson’s coffee-resque which is.

Resque for Node.js

Resque is a redis backed task queue inspired by delayed job. Node.js is a javascript runtime built on the v8 engine.


Resque.js allows you to chunk together blocks of concurrent code and work through them serially across multiple worker processes & machines. The advantage of building this as drop-in compatible resque workers is that the monitoring interface (resque-web) is already written and it provides a nice queue interface between Rails and node. You’re probably already running resque for Rails; use it for Node, too.


npm install resque If you don’t already have node_redis (redis on npm), npm will install it for you.



var sandwichWorker = exports

sandwichWorker.makeMeASandwich = function (sandwich) {
  var job = this
  makeSandwich (sandwich, function (err, result) {
    if (err) ({ error: err })
    else job.succeed ()

sandwichWorker.SomeRubyTask = function () {
    require ('sys').puts ("This task could have been pulled off a shared queue")
    this.succeed ()

success() and failure(error) callbacks are provided and can be passed in through async code to be called on completion, which frees up the worker to take another job off the queue.

Gentlemen, start your workers

To start the worker, WORKER=sandwich_worker.js QUEUE=sandwich_factory bin/node-resque-worker.
You can optionally provide a url to redis, like WORKER=sandwich_worker.js QUEUE=* bin/node-resque-worker

To stop the worker gracefully (finishing the last task), send a QUIT signal.
To stop the worker less gracefully, send a KILL signal.

Enqueueing tasks

#!/usr/bin/env node
var resque = require ("resque").connect ()
resque.enqueue ('sandwich_factory', 'makeMeASandwich',
  { bread: 'Acme Levain'
  , cheese: 'Cowgirl Creamery St Pat'
  , greens: ['arugula']
  , mustard: true

This code adds a makeMeASandwich request to the sandwich_factory resque queue.


By default, resque uses the redis namespace of resque:. If you require resque as follows, you can use a different namespace:

var resque = require ("resque").connect ({ namespace: "node-only" })

Providing a Redis connection

If you already are connected to redis in your app, you can use that client instead of creating a new one. To do so:

var redisClient = require ("redis").createClient ()
  , resque = require ("resque").connect ({ redis: redisClient })

Specifying Redis port & host

If Redis is not running locally or is not bound to the default Redis port & host (localhost:6379), you can provide port and host as follows:

var resque = require ("resque").connect ({ host: '', port: 1337 })

Cleaning stale workers

At any point, you can call require ("resque").connect({...}).cleanStaleWorkers (), which will ensure that any dead workers have been removed from resque. This is called at the start of node-resque-worker.