A queueing system to schedule jobs and have multiple rate-limited consumers.
npm install job-queueA queueing system to schedule jobs and have multiple rate-limited consumers.
``coffeescript`
jobQueue = new JobQueue consumers, limit, period
|Parameter|Type|Description|
|---|---|---|
|consumers|Function|A function that will accept a job as the only parameter.|limit
||Integer|The maximum number of jobs the consumer should process in period milliseconds.|period
||Integer|The number of milliseconds limit applies to.|
`coffeescript`
jobQueue.addConsumers consumers, limit, periodaddConsumers
Function signature for is same as the above constructor.
`coffeescript`
jobQueue.enqueue job
|Parameter|Type|Description|
|---|---|---|
|job|Anything| The job can either be any type (Object, Function, Number, ...). Its type depends on what the consumer takes as its argument.|
`coffeescript`
pendingJobs = jobQueue.pendingJobs
`coffeescript
JobQueue = require "job-queue"
makeConsumer = (consumerId) ->
(job) ->
console.log "Consumer #{consumerId} processing job #{job.id}"
job.process consumerId