🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mini-queue

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-queue

Job queue

0.0.6
Source
npm
Version published
Weekly downloads
8.6K
-1.51%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Build Status Coverage Status Code Climate Inch CI

Dependency Status devDependency Status

mini-queue

Job queue

If you have different needs regarding the functionality, please add a feature request.

Installation

npm install --save mini-queue

Usage

 QueueJob State Diagram (methods of JobQueue object)
 ======================

             |
   createJob |
      +------V-----+
      | new        |
      |            |
      +---+--+--+--+
          |  |  | _rejectJob                     +------------+
          |  |  +--------------------------------> reject     |
          |  |                                   |            |
_startJob |  | _queueJob                         +------------+
          |  +------------+
          |               |
          |         +-----v------+ _cancelJob
          |         | queue      +-----------------+
          |         |            |                 |
          |         +---+----^---+                 |
          | _dequeueJob |    |                     |
          |             |    |                     |
          |             |    | _queueJob           |
          |         +---v----+---+   _cancelJob  +-V----------+
          |         | dequeue    +---------------> cancel     |
          |         |            |               |            |
          |         +-----+------+               +------------+
          |               | _startJob
          |               |
          |    +----------+
          |    |
      +---v----v---+  _terminateJob       +------------+
      | process    +----------------------> terminate  |
      |            |                      |(not implem)|
      +-----+------+                      +------------+
            |
            |
            |
      +-----v------+
      | complete   |
      |            |
      +------------+

Example

You may find this example in demo subdirectory of the package.

"use strict";

process.env.DEBUG = 'queue,app';// + (process.env.DEBUG || '');
var debug   = require('debug')('app');


var Queue = require('express-queue');
//var Queue = require('../');
var queue = new Queue({ activeLimit: 1, queuedLimit: 1 });

// create jobs
var maxCount = 5,
    count = 0;

var interval = setInterval(function() {        
  var jobData = {};
  // Create new job for the queue
  // If number of active job is less than `activeLimit`, the job will be started on Node's next tick.
  // Otherwise it will be queued.
  queue.createJob(jobData); // we may pass some data to job when calling queue.createJob() function
  if (++count >= maxCount) {
    clearInterval(interval);
  }
}, 500);


// execute jobs

queue.on('process', function(job, jobDone) {
  debug('queue.on(\'process\'): ['+job.id+']');
  // Here the job starts
  // Imitate job processing which takes 1 second to be finished
  // job.data is set to value passed to queue.createJob()
  setTimeout(function() {
    // Call the callback to signal to the queue that the job has finished
    // and the next one may be started
    jobDone();
    // Now on Node's next tick the next job (if any) will be started
  }, 1000);
});

// Signal about jobs rejected due to queueLimit

queue.on('reject', function(job) {
  debug('queue.on(\'reject\'): ['+job.id+']');
});

Credits

Alexander

github.com   npmjs.com   travis-ci.org   coveralls.io   inch-ci.org

License

MIT

Keywords

job,queue

FAQs

Package last updated on 14 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts