callqueue
v1.0.4
Published
provide easy way to run one command at a time. Prepared for cron and longtime jobs with 1-size pipeline.
Downloads
9
Readme
callQueue
provide easy way to run one command at a time. Prepared for cron and longtime jobs with 1-size pipeline.
Install
npm install callqueue --save
Example
var callqueue = require("callqueue");
var sendEmails = callqueue(require.resolve("./lib/sendEmails.js"), ["method1", "method2"]);
...
["email1", "email2"].forEach(function(type) {
sendEmails.run.method1(type, function(err, result) {
});
});
Real example see in test dir.
Usage
require("callqueue")(fullLibPath, publicMethods, options);
- fullLibPath Can be a local lib require.resolve("./lib/sendEmails.js") or a some node module someModule
- publicMethods Write out all the lib public methods to expose it. Only these methods can be accesible through the callqueue api. All pubic method must be async and last their argument must be callback(err, results...)
- options object
- timeout in ms, timeouted job rise error in cb function
- workers set number of parallel workers
- parallelPerWork number of parallel jobs per worker.
API
- restart() wait for end all jobs and then restart all workers
- stop() wait for end all jobs and then stop all workers
- usage() return list of {pid: ##, usage: {cpu: ##, memory: ##}} for all running workers
- run.{method}(agrs...) wrapper for call the exposed methods. Args are same as original lib methods.
Events
callqueue wrapper rising a events.
- stop when all workers stopped
- restart after restarting all workers
- run(method, args) after call some method
History
- 1.0.1 add options
- 1.0.0 init release
License
(The MIT License)
Copyright (c) 2014 AoJ <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.