Created
October 8, 2012 09:32
-
-
Save kuno/3851636 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var spawn = require('child_process').spawn; | |
| var resque = require('coffee-resque').connect({ | |
| host: 'localhost', | |
| port: 6379 | |
| }); | |
| var mathJobs = { | |
| git: function(url, dest, callback) { | |
| var clone = spawn('git', ['clone', url, dest]); | |
| clone.on.('exit', function(code) { | |
| callback(code); | |
| }); | |
| }, | |
| cp: function(source, dest, callback) { | |
| var cp = spawn('cp', [source, dest]); | |
| cp.on('exit', function(code) { | |
| callback(code); | |
| }); | |
| }, | |
| add: function(a, b, callback) { callback(a + b); }, | |
| succeed: function(arg, callback) { callback(); }, | |
| fail: function(arg, callback) { callback(new Error('fail')); } | |
| } | |
| // setup a worker | |
| var mathWorker = resque.worker('math', mathJobs) | |
| // Triggered every time the Worker polls. | |
| mathWorker.on('poll', function(worker, queue) {}) | |
| // Triggered before a Job is attempted. | |
| mathWorker.on('job', function(worker, queue, job) {}) | |
| // Triggered every time a Job errors. | |
| mathWorker.on('error', function(err, worker, queue, job) {}) | |
| // Triggered on every successful Job run. | |
| mathWorker.on('success', function(worker, queue, job, result) { console.log(result); }) | |
| mathWorker.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment