node-resque
Advanced tools
Comparing version 0.2.4 to 0.2.5
exports.connection = require(__dirname + "/lib/connection.js").connection; | ||
exports.queue = require(__dirname + "/lib/queue.js").queue; | ||
exports.worker = require(__dirname + "/lib/worker.js").worker; | ||
exports.scheduler = require(__dirname + "/lib/scheduler.js").scheduler; | ||
exports.scheduler = require(__dirname + "/lib/scheduler.js").scheduler; |
@@ -12,4 +12,11 @@ var runPlugin = function(pluginName, type, func, queue, job, args, callback){ | ||
} | ||
var pluginConstructor = require(__dirname + "/plugins/" + pluginName + ".js")[pluginName]; | ||
var plugin = new pluginConstructor(self, func, queue, job, args, pluginOptions); | ||
var plugin = null | ||
if (typeof pluginName === 'string') { | ||
var pluginConstructor = require(__dirname + "/plugins/" + pluginName + ".js")[pluginName]; | ||
plugin = new pluginConstructor(self, func, queue, job, args, pluginOptions); | ||
} else if (typeof pluginName === 'function') { | ||
plugin = new pluginName(self, func, queue, job, args, pluginOptions); | ||
} else { | ||
throw new Error('Plugin must be the constructor name or an object'); | ||
} | ||
if(plugin[type] == null || typeof plugin[type] != "function"){ | ||
@@ -49,2 +56,2 @@ callback(null, true); | ||
exports.runPlugin = runPlugin; | ||
exports.runPlugins = runPlugins; | ||
exports.runPlugins = runPlugins; |
@@ -155,3 +155,3 @@ var os = require("os"); | ||
} else { | ||
self.completeJob(null, "Missing Job: " + job["class"], callback); | ||
self.completeJob(null, new Error("Missing Job: " + job["class"]), callback); | ||
} | ||
@@ -158,0 +158,0 @@ }catch(err){ |
@@ -5,3 +5,3 @@ { | ||
"description": "an opinionated implementation of resque in node", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"homepage": "http://github.com/taskrabbit/node-resque", | ||
@@ -8,0 +8,0 @@ "repository": { |
# node-resque | ||
Delayed Tasks in nodejs. A very opinionated but compatible API with [resque](https://github.com/resque/resque) and [resque scheduler](https://github.com/resque/resque-scheduler) | ||
[Find me on the NPM @ node-resque](https://npmjs.org/package/node-resque) | ||
[![Nodei stats](https://nodei.co/npm/node-resque.png?downloads=true)](https://npmjs.org/package/node-resque) | ||
@@ -37,3 +37,3 @@ [![Build Status](https://secure.travis-ci.org/taskrabbit/node-resque.png?branch=master)](http://travis-ci.org/taskrabbit/node-resque) | ||
perform: function(a,b,callback){ | ||
var answer = a + b; | ||
var answer = a + b; | ||
callback(answer); | ||
@@ -44,3 +44,3 @@ }, | ||
perform: function(a,b,callback){ | ||
var answer = a - b; | ||
var answer = a - b; | ||
callback(answer); | ||
@@ -114,3 +114,3 @@ }, | ||
The configuration hash passed to `new worker`, `new scheduler` or `new queue` can also take a `connection` option. | ||
The configuration hash passed to `new worker`, `new scheduler` or `new queue` can also take a `connection` option. | ||
@@ -135,4 +135,4 @@ ```javascript | ||
- `worker.workerCleanup()` only works for *nix operating systems (osx, unix, solaris, etc) | ||
- If you are using any plugins which effect `beforeEnqueue` or `afterEnqueue`, be sure to pass the `jobs` argument to the `new Queue` constructor | ||
- If you plan to run more than one worker per nodejs process, be sure to name them something distinct. Names **must** follow the patern `hostname:pid+unique_id`. For example: | ||
- If you are using any plugins which effect `beforeEnqueue` or `afterEnqueue`, be sure to pass the `jobs` argument to the `new Queue` constructor | ||
- If you plan to run more than one worker per nodejs process, be sure to name them something distinct. Names **must** follow the patern `hostname:pid+unique_id`. For example: | ||
@@ -147,3 +147,3 @@ ```javascript | ||
- **queue.prototype.queues** = function(callback) | ||
- **queue.prototype.queues** = function(callback) | ||
- callback(error, array_of_queues) | ||
@@ -161,4 +161,2 @@ - **queue.prototype.length** = function(q, callback) | ||
**TODO: have a way to load plugins so they don't need to be in this package** | ||
Just like ruby's resque, you can write worker plugins. They look look like this. The 4 hooks you have are `before_enqueue`, `after_enqueue`, `before_perform`, and `after_perform` | ||
@@ -214,3 +212,3 @@ | ||
perform: function(a,b,callback){ | ||
var answer = a + b; | ||
var answer = a + b; | ||
callback(answer); | ||
@@ -226,4 +224,22 @@ }, | ||
- There are a few included plugins, all in the lib/plugins/* directory. You can rewrite you own and include it like this: | ||
```javascript | ||
var jobs = { | ||
"add": { | ||
plugins: [ require('myplugin') ], | ||
pluginOptions: { | ||
myPlugin: { thing: 'stuff' }, | ||
}, | ||
perform: function(a,b,callback){ | ||
var answer = a + b; | ||
callback(answer); | ||
}, | ||
}, | ||
} | ||
``` | ||
## Acknowledgments | ||
Most of this code was inspired by / stolen from [coffee-resque](https://npmjs.org/package/coffee-resque) and [coffee-resque-scheduler](https://github.com/leeadkins/coffee-resque-scheduler). Thanks! |
@@ -12,3 +12,3 @@ describe('plugins', function(){ | ||
perform: function(a,b,callback){ | ||
var answer = a + b; | ||
var answer = a + b; | ||
setTimeout(function(){ | ||
@@ -23,6 +23,6 @@ callback(answer); | ||
perform: function(a,b,callback){ | ||
var answer = a + b; | ||
var answer = a + b; | ||
callback(answer); | ||
}, | ||
} | ||
} | ||
}; | ||
@@ -46,2 +46,23 @@ | ||
describe('custom plugins', function(){ | ||
it('runs a custom plugin outside of the plugins directory', function(done){ | ||
var jobs = { | ||
"myJob": { | ||
plugins: [ require('./custom-plugin') ], | ||
perform: function(a,b,callback){ | ||
done(new Error('should not run')) | ||
}, | ||
}, | ||
}; | ||
var queue = new specHelper.NR.queue({connection: specHelper.connectionDetails, queue: specHelper.queue}, jobs, function(){ | ||
queue.enqueue(specHelper.queue, "myJob", [1,2], function(){ | ||
queue.length(specHelper.queue, function (err, len) { | ||
len.should.equal(0); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('jobLock',function(){ | ||
@@ -125,3 +146,3 @@ it('will not run 2 jobs with the same args at the same time', function(done){ | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -137,3 +158,3 @@ }); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -182,2 +203,2 @@ }); | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61797
24
1567
238