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

jobman

v1.12.0

Published

Controllable and resonable job queue manager

Downloads

22

Readme

jobman

Controllable and resonable job queue manager

Build Status Coverage Status npm

Install

npm install --save jobman

Usage

The example code:

const jobman = require('jobman')

const man = jobman({  // create new jobman object
  max: 3,  // max concurrent jobs
  jobStart: (job, man)=>{  // when A job will start
    if(job.prop==5) return false  // return FALSE will cancel the job
  },
  jobEnd: (job, man)=>{  // when A job did end
    console.log('result: ', job.prop, job.error || 'ok')
  },
  jobTimeout: (job, man)=>{  // when A job timeout
    console.log('timeout: ', job.prop)
  },
  allStart: (info, man)=>{  // all jobs will start
    console.log('all jobs will start')
  },
  allEnd: (info, man)=>{  // all jobs done
    console.log('all end', man.isDone)
    // also clear all pending jobs, cancel running callbacks
    man.clear(true)
  },
  autoStart: true  // start monitor when create
})

for(let i=0;i<10;i++){
  man.add(cb=>{  // add A job
    task(i, cb)
  }, i)  // job.prop = i
}

man.add(0, cb=>{  // insert A job into 0 index
  task(99, cb)
}, {id: 'insert to first!', timeout: 500})  // the job timeout is 500ms

function task(i, cb){  // dummy task function
  setTimeout(()=>{
    if(i==3) cb('bad')  // cb with error
    else cb()  // cb with ok
  }, 1000)  // async happen at 1 second
}

The result:

all jobs will start
timeout:  { id: 'insert to first!', timeout: 500 }
result:  0 ok
result:  1 ok
result:  2 ok
result:  3 bad
result:  4 ok
result:  6 ok
result:  7 ok
result:  8 ok
result:  9 ok
all end true

API

jobman(config) -> manObject

  • config

    • config.max int

      max number of concurrence jobs.

    • config.timeout int

      ms to wait for --A job--, trigger jobTimeout event after the time

    • config.interval int

      ms to pass into setInterval check internally

    • config.jobTimeout fn(job, man)->boolean

      callback function after --A job-- timeout, return false will book another timeout

    • config.jobStart fn(job, man)->boolean

      callback function before --A job-- will start, return false will cancel this job

    • config.jobRun fn(job, man)->void

      callback function after --A job-- did start, job.state become run

    • config.jobEnd fn(job, man)->void

      callback function after --A job-- callback invoked, with man.lastError set to result error

    • config.allStart fn(info, man)->void

      callback function before --ALL job-- start run, useful for init, info is user passed with man.start(info)

    • config.allEnd fn(info, man)->void

      callback function when --ALL job-- finished run, info is user passed with man.end(info)

  • manObject

    • man.add([position:int], jobFn:cb=>{}, jobProp:any)

      jobFn is with callback for one job, cb(err) have to be called for each job. jobProp will become job.prop

    • man.start([info])

      function to start current jobman, use man.stop to stop it, trigger man.allStart with first arg set to info

    • man.stop()

      function to stop current jobman, use man.start to start again

    • man.end([info], [cancelPending])

      trigger man.allEnd with first arg set to info, cancelPending will cancel pending jobs

    • man.clear(cancelRunningJobs)

      Remove all pending jobs, cancel running jobs if cancelRunningJobs is true

    • man.config object

      the config object passed into jobman

    • man.jobs array

      the jobs array internally, query for it for state, length etc.

    • man.isRunning boolean

      prop to get if the job monitor is is running (not stopped)

    • man.isDone boolean

      prop to get if all job ended

    • man.pending [jobObject, ...]

      prop to get pending jobs in queue

    • man.running [jobObject, ...]

      prop to get running jobs in process

    • man.slot int

      prop to get current available job runner slot

    • man.startCount int

      jobman start counter, from 0, after first start() will be 1, after next start() plus 1

  • jobObject

    • job.fn function

      the jobFn function passed into man.add()

    • job.error any

      when job callback called with error, set to it with the error

    • job.prop any

      the prop to passed into man.add()

    • job.prop.timeout int

      set timeout for individual job

    • job.state any

      internal state for each job, value is run/done/error/timeout/cancel