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-schedule

v1.1.2

Published

Schedule Jobs for run one time

Downloads

14

Readme

job-schedule

Schedule job for run one time.

This is similar to PriorityQueue

Creates a queue object with the specified concurrency. Tasks added to the queue are processed in parallel (up to the concurrency limit). If all workers are in progress, the task is queued until one becomes available. Once a worker completes a task, that task's callback is called.

However, it can specific running-condition for the task. This is very useful to schedule the time based jobs for run one time only.

Install

$ npm i -S job-schedule

API

// parameters and return value if similar to `priorityQueue`
let q = new Queue(worker, concurrency)

// Start task when this function returns `true`
// Call `cb` to resume the queue `q`
q.when = function (node, cb) {
  if (someConditions(node)) {
    return true
  }
  doSomething(() => cb())
}

// remove jobs with condition
// true: removing job
q.remove(node => {
  if (matched(node)) {
    return true
  }
  return false
})

Example

const Queue = require('job-schedule')

var timerId = null
var q = new Queue((task, cb) => {
  console.log('priority:hello', task.name)
  cb()
}, 1)

// node: {  priority, data }
q.when = function (node, cb) {
  // start task if it's priority less than 2
  if (node.priority -- < 2) {
    clearTimeout(timerId)
    console.log('start:', node.data.name)
    return true
  }
  // resume queue after 1s
  timerId = setTimeout(cb, 1000)
}

// call when all tasks finished
q.drain = function () {
  console.log('all items have been processed')
}

// add some items to the queue
q.push({name: 'foo'}, 10, function (err) {
  console.log('finished processing foo', err)
})
q.push({name: 'bar'}, 2, function (err) {
  console.log('finished processing bar', err)
})

// add some items to the queue (batch-wise)
q.push([{name: 'baz'}, {name: 'bay'}, {name: 'bax'}], 6, function (err) {
  console.log('finished processing item', err)
})

Prior art

async