npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jobq

v1.0.12

Published

Async and parallel execution of jobs, tasks and processes with a queue manager

Downloads

42

Readme

Build Status

jobQ

Async and parallel execution of jobs, tasks and processes. This library is aimed to solve the problem of having to limit how many parallel tasks you want to perform. It accepts several kinds of sources including Arrays, Promises, Functions, etc.

Installation

npm install --save jobq

Usage

var jobQ = require('jobq')

var queue = new jobQ({
  process: function(x, callback){
    setTimeout(function() {
      callback(null, x)
    }, 3000)
  },
  source: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  maxProceses: 2
})

queue.start()

Options

  • source: required View source section.
  • process: required View process section.
  • maxProceses: <Number> indicates how many jobs will run in parallel. A value of 0 means 'no limit'. Default 1
  • debug: <Boolean> enables or disables debug. Default false
  • stopOnError: <Boolean> indicates if jobs will stop after first error or continue. If enabled, processFinish will be called with status error if an error occurs. Default false
  • pooling: <Number> pooling timeout in milliseconds. When enabled, JobQ will continue to try and fetch data from the source (Function only). Default: No pooling

Events

var queue = new jobQ({
  process: myProcess,
  source: mySource,
  maxProceses: 2
})

queue.on('start', function(){})
queue.on('jobFetch', function(){})
queue.on('jobRun', function(){})
queue.on('jobFinish', function(){})
queue.on('processFinish', function(){})
queue.on('pooling', function(){})
queue.on('pause', function(){})
queue.on('resume', function(){})
queue.on('error', function(){})

queue.start()

start

Emited once after calling start() with an object containing:

  • startTime: <Date> date when start was called
  • processed: <Number> jobs processed so far
  • errors: <Number> jobs errored so far
  • maxProceses: <Number> maxProceses passed to constructor. Default 1
  • stopOnError: <Boolean> stopOnError passed to constructor. Default false
  • sourceType: <String> Detected source type (array, function, promise or stream).
  • status: <String> queue status. will always be running at this point.

jobFetch

Emited once for each job before fetching it from the queue with an object containing:

  • jobsRunning: <Number> current amount of processing jobs. It will not count the one that triggered the event.

jobRun

Emited once for each job when it starts running with:

  • <number> job id (autoincrement)

jobFinish

Emited once after calling start() with an object containing:

  • jobId: <Number> job id
  • jobStartTime: <Date> date when job started to process
  • jobEndTime: <Date> date when job finishes to process
  • result: <any> job result received
  • jobsRunning: <Number> current amount of processing jobs. It will count the one that triggered the event.

processFinish

Emited once after calling start() with an object containing:

  • startTime: <Date> date when start was called
  • endTime: <Date> date when queue was fully processed
  • processed: <Number> total amount of jobs processed
  • errors: <Number> total amount of errors
  • maxProceses: <Number> maxProceses passed to constructor. Default 1
  • stopOnError: <Boolean> stopOnError passed to constructor. Default false
  • sourceType: <String> Detected source type (array, function, promise or stream).
  • status: <String> queue status. will always be finished or error.

pooling

Emited every time the source function returns null as value and JobQ starts waiting to check again. Only emited if pooling is enabled, with an object containing:

  • startTime: <Date> date when start was called
  • processed: <Number> jobs processed so far
  • errors: <Number> jobs errored so far
  • maxProceses: <Number> maxProceses passed to constructor. Default 1
  • stopOnError: <Boolean> stopOnError passed to constructor. Default false
  • sourceType: <String> Detected source type (array, function, promise or stream).
  • status: <String> queue status. will always be pooling at this point.

pause

Emited once after calling pause() with an object containing:

  • startTime: <Date> date when start was called
  • processed: <Number> jobs processed so far
  • errors: <Number> jobs errored so far
  • maxProceses: <Number> maxProceses passed to constructor. Default 1
  • stopOnError: <Boolean> stopOnError passed to constructor. Default false
  • sourceType: <String> Detected source type (array, function, promise or stream).
  • status: <String> queue status. will always be paused at this point.

resume

Emited once after calling resume() with an object containing:

  • startTime: <Date> date when start was called
  • processed: <Number> jobs processed so far
  • errors: <Number> jobs errored so far
  • maxProceses: <Number> maxProceses passed to constructor. Default 1
  • stopOnError: <Boolean> stopOnError passed to constructor. Default false
  • sourceType: <String> Detected source type (array, function, promise or stream).
  • status: <String> queue status. will always be running at this point.

error

Emited once for each job error:

  • <Error> error received

Source

Source is where data will be fetched in order to be processed. It can be one of the following:

  • <Array> like [1, 2, 3].
  • <Array> of promise like [promise1, promise2, promise3].
  • <Function> returning a value.
  • <Function> returning a promise.
  • <Function(callback)> returning nothing and passing data to callback with error as the first parameter and response as the second one.
  • <ReadableStream> that supports on('readable') and read().
  • <Promise> that resolves to any of the previous source types.

IMPORTANT: When using Function and Promise sources, you must pass null as value to stop execution.

Process

Process function receives a value from the queue and be anby of the following:

  • <Function> that returns a value
  • <Function> that returns a Promise wich resolves to a value
  • <Function(callback)> that returns nothing and executes a callback with error as the first parameter and response as the second one.