• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    JavaScript
  • Created over 14 years ago
  • Updated almost 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Resque for Node.js (pure JS)

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.

Why?

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.

Install

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

Use

sandwich_worker.js

var sandwichWorker = exports

sandwichWorker.makeMeASandwich = function (sandwich) {
  var job = this
  makeSandwich (sandwich, function (err, result) {
    if (err) job.fail ({ 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=* REDIS=redis.example.com:9876 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.

Namespaces

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: 'redis.production.example.com', 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.

More Repositories

1

sibilant

Just another compile-to-js LISP-like language
JavaScript
385
star
2

jQuery.highlightRegex

jQuery Plugin that lets you highlight document text with a regular expression.
JavaScript
101
star
3

tide-example

an example application for tide using askama and sqlx, modeled closely after the rails getting started tutorial
Rust
41
star
4

async-redis-session

Rust
35
star
5

async-sqlx-session

Rust
29
star
6

longboard

Longboard: The easy way to surf
Rust
19
star
7

driftwood

some logs on the tide
Rust
17
star
8

argonaut

Lightweight JSON builder for Rails
Ruby
17
star
9

tide-tera

Rust
16
star
10

stately.js

state machine dsl for node
JavaScript
15
star
11

routefinder

Rust
12
star
12

tide-serve

Rust
12
star
13

follow-that-bird

An implementation for Tweak-the-Tweet style emergency-response twitter syntaxes
JavaScript
12
star
14

sugarcube

Oh it's work all day for the sugar in your D3
JavaScript
8
star
15

test-harness

Rust
7
star
16

lol-async

Rust
7
star
17

feel

it goes beyond touch
Rust
6
star
18

breakglass

In case of emergency...
Ruby
5
star
19

rubydoop

Simple Ruby Sugar for Hadoop Streaming
Ruby
5
star
20

dbplot

SQL-like query in, PDF out (with R, ggplot2, and ruby)
Ruby
5
star
21

littoral

Rust
5
star
22

tweak-the-tweet

4
star
23

stopper

Rust
4
star
24

rcr-notify

Growl poller for runcoderun
Ruby
4
star
25

pushcar

Comet (ajax push) inside of rails, based on pusher, using thin + eventmachine.
Ruby
3
star
26

smartcow

Rust
3
star
27

resque-monitor

resque-web in node.js
3
star
28

surf-cookie-middleware

Rust
3
star
29

url_param

rails plugin that handles parameter generation
Ruby
2
star
30

test-rig

TestRig supplies dynamic assertions and contextual failure messages
Ruby
2
star
31

waker_set

Rust
2
star
32

enumerable-proxy

A pattern for simple block-free ruby enumeration
Ruby
2
star
33

resourceful

A lightweight resource loader macro for Rails
Ruby
2
star
34

sibilant-react

sibilant macros for react
JavaScript
1
star
35

jQuery.delay

A little delay jQuery plugin
JavaScript
1
star
36

dotfiles

nothing to see here
1
star
37

stochastic-vacuum-mdp

Clojure
1
star
38

sketchy

JavaScript
1
star
39

field_marshal

just a little experiment in marshalling ruby procs
Ruby
1
star
40

sibilant-webpack-loader

JavaScript
1
star
41

treesl

DSL definition tool
Ruby
1
star
42

freighthopper

Some extensions for riding the rails
Ruby
1
star
43

Norm

A minimal just-in-time Ruby MySQL Object Map
Ruby
1
star
44

jbr.github.com

JavaScript
1
star
45

sibilant-gem

Ruby gem for the sibilant compiler
Ruby
1
star
46

ShareLocally

Repository for the RailsRumble 2009 Team 237
Ruby
1
star
47

simply_stated

Yet another ruby state machine. ActiveRecord-specific, simple DSL.
Ruby
1
star
48

querystrong

Rust
1
star
49

testy

JavaScript
1
star
50

sibilant-macros

A hodgepodge of macros for common libraries and environments
1
star