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

node-runners

v1.2.0

Published

Execute set of predefined tasks at a given time/times and at certain interval/s.

Downloads

1

Readme

node-runners

This package has been renamed to 'node-runnr'.

Please visit : https://www.npmjs.com/package/node-runnr

node-runnr is easy to use task master. Execute set of predefined tasks at a given time/times and at certain interval/s.

Usage

Install using npm:

npm install node-runnr

Overview

'node-runnr' can execute an arbitrary task at multiple intervals and time. Unlike cron, input time format are in Human readable form. You can run jobs daily, weekly or monthly at multiple time/date. It exposes few APIs through which all jobs can be reschedules/stopped/start via front-end (You need to make a front-endfor that.)

It have just one clock to monitor all jobs thus no need to re-evaluate jobs at every cycle, hence, its very lightweight. By default, clock cycle is 100ms i.e check and ecxecute task at every 100ms. However, custom cycle can be passed while creating a runnr object.

Jobs and scheduling

Require node-runnr.

var Runnr = require('node-runnr');
var Jobs = new Runnr();

For custom job cycle.

var Jobs = new Runnr(200);

Time format looks as follow:

Day:Hour:Min:Sec

For example, '2: 12:30: 10' would run a job at every 2 days, 12 hour, 30 min and 10 seconds if its an interval job.

If its a monthly job, it will execute job on 2nd of every month at 12:30:10.

If its a weekly job, Monday, 12:30:10 every week.

To execute job at every 5 min, time string would be just 5:0, and just 5 for every 5 sec and so on.

Creating Jobs.

node-runnr exposes four functions to create a job. All functions returns the name of job created.

  1. Creating an Interval job:

    var interval = Jobs.addIntervalJob('10:20', function(){...}, 'myjob', details);
    console.log(interval); 		// Output -> myjob
    // typeof 'details' is should be object

    This will create a job named 'myjob' and execute at every 10 min and 20 seconds. We can set multiple intervals.

    var interval = Jobs.addIntervalJob(['5', '10', '20'], function(){...}, 'myjob', details);
    console.log(interval); 		// Output -> myjob

    This will execute job at 5 min, then 10 min after last execyte time, then 20 min after last time and then 5, and so on.

  2. Creating a daily job:

    var daily = Jobs.addDailyJob('10:20', function(){...}, 'myjob', details);
    console.log(daily); 		// Output -> myjob

    This will create a job at 00:10:20(00hr 10min 20sec). To create a job at 9:25 PM, enter 21:25:00.

    To execute a job at multiple time, i.e 9AM, 3PM, 10:30PM do as follow.

    var daily = Jobs.addDailyJob(['9:0:0', '15:0:0', '22:30:0'], function(){...}, 'myjob', details);
    console.log(daily); 		// Output -> myjob
  3. Creating a weekly job: Day: 1-7, 1-Sunday, 7-Saturday

    var weekly = Jobs.addWeeklyJob('2:0:10:20', function(){...}, 'myjob', details);
    console.log(weekly); 		// Output -> myjob

    This will create a job on Monday, at 00:10:20(00hr 10min 20sec).

    To execute a job at multiple days, i.e Sunday 9AM, Tuesday 3PM, Friday 10:30PM do as follow.

    var weekly = Jobs.addWeeklyJob(['1:9:0:0', '3:15:0:0', '6:22:30:0'], function(){...}, 'myjob', details);
    console.log(weekly); 		// Output -> myjob
  4. Creating a monthly job: Date: 1-31 (If month have 30 days, 31st job will be done on 1st of coming month)

    var monthly = Jobs.addMonthlyJob('2:0:10:20', function(){...}, 'myjob', details);
    console.log(monthly); 		// Output -> myjob

    This will create a job on 2nd, at 00:10:20(00hr 10min 20sec) of every month.

    To execute a job at multiple dates, i.e 1st 9AM, 15th 3PM, 25th 10:30PM do as follow.

    var monthly = Jobs.addMonthlyJob(['1:9:0:0', '15:15:0:0', '25:22:30:0'], function(){...}, 'myjob', details);
    console.log(monthly); 		// Output -> myjob

    Note: Name must be unique for all job.

Stop/cancel a job:

var stopped = Jobs.stop('myjob')
console.log(stopped);		// true or false

To stop all running jobs.

var stopped = Jobs.stopAll()
console.log(stopped);		// true

To remove a job forever -

var kill = Jobs.kill('myjob')
console.log(kill);		// true / false

Start a stopped job

var start = Jobs.start('myjob')
console.log(start);		// true or false

To stop all running jobs.

var start = Jobs.startAll()
console.log(start);		// true

Rescheduele a job

var job = Jobs.reschedule(interval, '20:10');
console.log(job);		// myjob. (interval = 'myjob')

Get job

var job = Jobs.get(daily);
console.log(job);
/* Output
{
	name: 'myjob',
	last: Number,	// Last run timestamp
	next: Number,	// Next scheduled run timestamp
	pause: Boolean,	// Stopped or running
	type: 'daily',
	_schedule: String,	// entered time/interval string
	schedule: Array,	// Evaluated timestamp or interval in ms
	details: Object,	// Whatever object was entered during job creation
}
*/