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

job-manager

v0.0.4

Published

A queue manager class which process tasks with given workers, with adjustable concurrency. It can automatically load tasks, pause resume etc

Downloads

18

Readme

node-job-manager

JobManager is a multipurpose, flexible, asynchronous queue manager class written in Nodejs. Queue is processed using given workers. It is possible to change concurrency and load bulk tasks at run time. See demo for better understanding

Overview

A JobManager instance need the following informations to get started. They are,

  • workers: An array of worker instances that are used to do the work.
  • onLoadMore: A function that tells how to retrieve tasks that need to processed with workers.
  • work: a function that does the real task. It is called with following syntax: worker( task, worker, cb ). task and worker are are belongs to the available tasks and workers. cb is the callback function that should be called after work is done.
  • onError: A function that is called when a Error is occurred during 'work' function. it is called with following syntax: onError(err, task, worker);
  • onStopped: A function that is called when all tasks are processed.

JobManager instance is controlled by the following configuration options

  • concurrency: An integer that tells how many workers should be run a time. Note that, concurrency cab be higher than no.of workers. In this case, one worker may be used to process more than one task at a time.
  • minConcurrency: An integer. concurrency can not be decreased below this value.
  • notifyAt: if ( no.tasks/concurrency < notifyAt ), onLoadMore function is called to fetch more tasks.
  • endReached: A Boolean. if it is set to true, onLoadMore will not be called further. and thus, execution of JobManager will stop after processing all the currently available tasks.
  • setConcurrency: A function that is used to change concurrency at runtime.

Following variables reveals current state of JobManager instance.

  • state: NOT_RUNNING | RUNNING.
  • isLoadingTakingPlace: onLoadMore function is taking place.

Usage

var JobManager = require('job-manager').JobManager;
var jm = new JobManager({ configuration options});
jm.workers = workers;
jm.onLoadMore = function(cb){// code; if( !tasks ){ this.endReached = true; }  cb()}
jm.work = function(task, worker,cb){ // worker.process( task, cb ); }
jm.onError = function( err, task, worker){ // log( err,  task, worker ); }
jm.onStopped = function(){ // log('Finished'); cb(); }
jm.start();
// jm.stop();

Demo

A pure javascript demo at http://harish2704.github.io/jobmanager-demo/test.html will give a more cleat idea. This demo uses the same JobManager class to do the animation.

Self promotion

  • I am a javascript freelancer. You can hire me.
  • star my repos.