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

audiot-node-job-manager

v1.0.0

Published

A wrapper Object for node-cron that allows you to manage multiple cron jobs at once.

Downloads

2

Readme

audiot-node-job-manager

A Cron Job Manager to maintain collections of Jobs and provide a method to control reuse and redefinition of those jobs. This is based on a fork from cfurst/CronJobManager which wraps node-cron .

Installation

npm install audiot-node-job-manager

Synopsis

var CronJobManager = require('audiot-node-job-manager'),
manager = new CronJobManager( // this creates a new manager and adds the arguments as a new job.
'a_key_string_to_call_this_job',
'0 30 * * * *', // the crontab schedule
function() { console.log("tick - what should be executed?") },
{
// extra options.. 
// see https://github.com/ncb000gt/node-cron/blob/master/README.md for all available
  start:true,
  timeZone:"America/Los_Angeles",
  completion: function() {console.log("a_key_string_to_call_this_job has stopped....")}
} 
);
manager.add('next_job', '0 40 * * * *', function() { console.log('tick...')});
manager.start('next_job');
manager.stop('a_key_string_to_call_this_job');
manager.exists('next_job') //true
manger.update('a_key_string_to_call_this_job', 
  "0 */2 * * * *", 
  function() {console.log("now running this job every two minutes, using this function..."});
console.log("current jobs are: " + manager);

Create a Manager

creating a manager object is easy, you can create one with arguments that become a new job, or just create one to add jobs to later:

var manager1 = new CronJobManager('a key to identify the job', 
  '30 * * * * *', 
  taskFunction,
  {
    start: true, 
    completion: taskCompleteFunction, 
    timeZone:"Australia/Sydney"
  }),
manager2 = new CronJobManager();

the final options object is optional, these are options that are past to node-cron and they include the following:

  • start: true/false
  • completion: function - runs when the job is stopped
  • timeZone: MUST have time installed for this work - see the node-cron readme for more details.

Adding jobs

jobs are added with arguments similar to the above with the add function:

manager.add('key','* 30 * * * *', taskFunction)

in this case with the final options object left out of the arguments, the job will be created with the defaults as per node-cron, this means the job will not start until you tell it to, there will be no completion function and the time zone will default to whatever you have your node.js process to use.

If the key you are using already exits in the manager, that key will be overwriten, the original job will stop and this one will take its place. A warning will be printed to the log when this happens.

Starting Jobs

To start a job you can use the start function

manager.start('key')

Stopping Jobs

Stopping is the same as start with the stop function

manager.stop('key')

Stopping All Jobs

To just stop all the jobs in the manager use stopAll

manager.stopAll()

Any arguments are ignored.

Updating jobs

You may want to change the task, time or both of any job during execution. You can do so using the update function

manager.update('key', '0 15 3,5,9,14,18,20 * * *', function() {// do this instead on this new schedule
});
manager.update('key', function)() { // do this instead 
});
manager.update('key', '0 15 3,5,9,14,18,20 * * *') // do it on this schedule instead.

the old job on the old schedule will be stopped, changed and started again if it was running when you called update. If you are just changing the function, the job will continue to use the current scheudle. If you are just changing the schedule the job will continue to use the current function.

Deleting jobs

you can delete any currently stopped or running jobs using the deleteJob function

manager.deleteJob('key')

The job will be stopped and then removed from the manager, any attempt to alter key after deletion will result in an error message to the log since it no longer exists.

Viewing jobs

if you want to see what jobs you have set up, you can just pass your manager as a string. It will display a formatted list of jobs, and their crontabs, and if they have a function to run.

console.log("I got the current jobs: " + manager)

If you need more details or would like to pass the string somewhere else you can use the listCrons function

var jobs = manager.listCrons();
doSomethingWithJobList(jobs);

Checking for existing jobs

To check to see if a job exists with a specific key use the exists function

if (manager.exists('key')) console.log("key exists");