Skip to content

Commit

Permalink
update ruby and add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Tahler committed Jan 16, 2014
1 parent f9a8857 commit 874dced
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 12 deletions.
81 changes: 81 additions & 0 deletions examples/errorExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/////////////////////////
// REQUIRE THE PACKAGE //
/////////////////////////

var NR = require(__dirname + "/../index.js");
// In your projects: var NR = require("node-resque");

///////////////////////////
// SET UP THE CONNECTION //
///////////////////////////

var connectionDetails = {
host: "127.0.0.1",
password: "",
port: 6379,
database: 0,
// namespace: "resque",
// looping: true
}

//////////////////////////////
// DEFINE YOUR WORKER TASKS //
//////////////////////////////

var jobsToComplete = 0;
var jobs = {
"brokenJob": {
plugins: [],
pluginOptions: {},
perform: function(a,b,callback){
jobsToComplete--;
shutdown();

MISSING_VAR + THING;

callback(null);
},
},
};

////////////////////
// START A WORKER //
////////////////////

var worker = new NR.worker({connection: connectionDetails, queues: ['default']}, jobs, function(){
worker.workerCleanup(); // optional: cleanup any previous improperly shutdown workers
worker.start();
});

/////////////////////////
// REGESTER FOR EVENTS //
/////////////////////////

worker.on('start', function(){ console.log("worker started"); })
worker.on('end', function(){ console.log("worker ended"); })
worker.on('cleaning_worker', function(worker, pid){ console.log("cleaning old worker " + worker); })
worker.on('poll', function(queue){ console.log("worker polling " + queue); })
worker.on('job', function(queue, job){ console.log("working job " + queue + " " + JSON.stringify(job)); })
worker.on('reEnqueue', function(queue, job, plugin){ console.log("reEnqueue job (" + plugin + ") " + queue + " " + JSON.stringify(job)); })
worker.on('success', function(queue, job, result){ console.log("job success " + queue + " " + JSON.stringify(job) + " >> " + result); })
worker.on('error', function(queue, job, error){ console.log("job failed " + queue + " " + JSON.stringify(job) + " >> " + error); })
worker.on('pause', function(){ console.log("worker paused"); })

////////////////////////
// CONNECT TO A QUEUE //
////////////////////////

var queue = new NR.queue({connection: connectionDetails}, jobs, function(){
queue.enqueue('default', "brokenJob", [1,2]);
jobsToComplete = 1;
});

var shutdown = function(){
if(jobsToComplete === 0){
setTimeout(function(){
worker.end(function(){
process.exit();
});
}, 500);
}
}
28 changes: 16 additions & 12 deletions resque-web/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
GEM
remote: http://rubygems.org/
specs:
atomic (1.1.14)
mono_logger (1.1.0)
multi_json (1.8.2)
multi_json (1.8.4)
rack (1.5.2)
rack-protection (1.5.1)
rack-protection (1.5.2)
rack
rake (10.1.0)
redis (3.0.5)
redis-namespace (1.3.2)
rake (10.1.1)
redis (3.0.6)
redis-namespace (1.4.1)
redis (~> 3.0.4)
resque (1.25.1)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-scheduler (1.9.9)
redis (>= 2.0.1)
resque (>= 1.8.0)
rufus-scheduler
rufus-scheduler (2.0.10)
tzinfo (>= 0.3.23)
resque-scheduler (2.3.1)
redis (>= 3.0.0)
resque (~> 1.25)
rufus-scheduler (~> 2.0)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
tzinfo (0.3.37)
tzinfo (1.1.0)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)

Expand Down

0 comments on commit 874dced

Please sign in to comment.