Distributed task queue for node.js
Distributed priority task queue for node.js with connection-pooling and the ability to enforce uniqueness constraints.
Note: this repository is still in early development. My company is using it in production. While the core API is in place, we are looking for initial users and contributors.
npm install taskco
// Begin by creating a factory:var TaskCo = require'taskco'setup;// Add team to process tasks named "email" using the processEmail function// This team has 3 concurrent workers removes tasks 5 seconds after completion/failure.TaskCoaddProcedure'email' processEmail removeAfter : 5 andTeam3;// Create task : if uid is set, it will, in conjuction with the type of task (email)// enforce uniqueness of that task.TaskCoquickEntry'email' name : 'email@example.com' uid : 'uniqueid' ;
Note: While a TaskCo supports multiple factories, the root object has convenience accessors for the default factory. The following example uses those methods.
A procedure consists of at least one function,
var processEmail =console.logtaskdataname;done;
Tasks can have a priority of any number. The higher the number, the higher the priority. Default priority levels include "low", "normal", "medium", "high", and "critical". Please see examples/priority.js for usage.
TaskCo is created to handle shutdowns as gracefully as possible. You are responsible for signaling the shutdown to TaskCo. You should also provide an estimate of the number of seconds until failure if possible. For example, Heroku triggers a SIGTERM and leaves 10 seconds for cleanup.
processon"SIGTERM"// !!! NOTE THAT TIME TO LIVE MUST BE GREATER THAN 2 SECONDS (DURATION OF BLOCK POP)TaskCoshutdown10;;
TaskCo proceeds with the following sequential steps:
- Affected Factories are told to commence shutdown process.
- Dispatcher halts retrieving next tasks.
- Teams are told to commence shutdown process.
- Teams log active tasks into
purgatory, along with timestamps.
- Dispatcher shuts down and broadcasts termination.
- Pooled connections are shut down.
- New or sibling processes parse through purgatory to find tasks w/action needed.
These are the top priorities currently:
- Optional logging (to be used for error handling) - this is the first step toward the "monitor".
- Better error handling (promises consume a lot of errors...should consider emitting them).
- More tests! I'd like to get a great test suite in place to facilitate pull requests.
- Separate http server: I prefer to separate this into an additional repo.
TaskCo was created with the following features in mind:
- Extremely modular design: enables easier collaboration.
- The ability to drop in a store. Currently, Redis is the only supported store.
- Connection pooling.
- Task-routing-friendly: while not currently implemented, the infrastructure was design with this in mind.
- Easy input/output. Lots of convenience functions.
- As much auto-cleanup as possible (frequent use of
- The ability to enforce task uniqueness.
- An extensive test suite (help needed here)
This project started in search of a redis-backed tasks queue. While there are numerous options at the time of publishing, each of these has its benefits/shortcomings. These are in NO way knocks against the projects, or against the authors, they simply highlight why we are in need of another solution.
Kue (LearnBoost): the most mature, and certainly most beautiful queue around. Fast, and clean code base. Large portions of this repository were inspired by Kue. Unfortunately, the repo has numerous pull requests outstanding, does not offer connection pooling, tends to have problems cleaning up tasks, and operates a first-come-first-serve queue.
Kue (dfoody): updated with numerous quality-of-service features, it still suffers from lack of connection pooling, and has not been shown to be compatible past node 0.6.x. To my knowledge, it also does full text indexing in the manner of Kue (LearnBoost).
Convoy: Great work by GoSquared to prevent jammed tasks. Currently does not offer storing additional data (a necessity for many).
Coffee-Resque: a great start in porting Github's own resque, however, the project appears to be not nearly as fully-featured.
(The MIT License)
Copyright (c) 2013 Brandon Carl <firstname.lastname@example.org>
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.