Simple pausable id based queue system with shortage notification
Simple pausable id based queue system with shortage notification and priority
npm install drainage
var drainage = require'drainage';// concurrency is by default 1 and there is no priority. In this example// the concurrency is 100// the priority of a task can be a integer between 0 and 10,// small intervals is best for performancevar queue = drainageconcurrency: 100 priority: 0 10processnextTickconsole.logtaskmessage;// Call done when the task has been handled or failed to do soqueuedonetask;;;// All tasks must have some id, and priority is used it must also have a priority// number. Note that `drainage` perform no validation of this!queuepushid: 0 priority: 5 message: 'hallo world';queueon'shortage'// `amount` is a number there is >= 0 and indicates the needed amount of tasksif amount === 0// The amount of tasks there are in progress is equal to the max concurrency// you should consider pulling more tasks since there will soon be a shortageelse// The amount of tasks there are in progress is less than the max concurrency// you should really pull more tasks if possible;// Tasks in the queue will not be processed, tasks there are in process can still// be completedqueuepause;// Start processing tasks, no need to call this unless `.pause` has been calledqueueresume;// Maybe you have some job event that drainage isn't aware of, in that case call// the fetch. This will emit the shortage event, but only if there is a shortage.processon'SIGPOLL'queryfetch;;
The software is license under "MIT"
Copyright (c) 2013 Andreas Madsen
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.