timebot

Simple cron bot for node - no dependencies!

npm install timebot
2 downloads in the last week
9 downloads in the last month

timebot

Simple NPM module for running cron jobs

Installation

npm install timebot

Usage

var timebot = require('timebot');

timebot.set({
    path:'foo',
    day:'11',
    month:'3-7'
},{
    cron:function(D){
        //D is the Date object for the current time
        console.log(D);
    }
});

Timebot set takes in two JSON objects as parameters. The first defines the options of the cron you wish to set. The second defines the callbacks that will be triggered by the cron job.

Options

Path

path (str): The path string defines the cron you are setting. It is a unique identifier for the job. This is useful to keep track of multiple cron jobs or for overwriting or cancelling jobs. If not defined, the path will default to '1' for the first job and '2' for the second, etc.

Minute

minute (num or str): The minute defines the minute values you would like the cron to run on. If not defined, the cron will run on every minute.

Examples:

  • 1 - cron will run on the first minute of each hour, ex: 4:01, 5:01, 6:01
  • '5-12' - cron will run for every minute between 5 and 12, ex: 4:05, 4:06, ... 4:12
  • '5,11,16' - cron will run for the listed minute values, ex: 4:05, 4:11, 4:16
  • '1-10,16' - cron will run for the range specified and for the listed values, ex: 4:01, 4:02, ... 4:10, 4:16
  • (no value) - cron will run every minute, ex: 4:01, 4:02, 4:03, ...

Hour

hour (num or str): The hour defines the hour values you would like the cron to run on. Values may be defined in the same way as minute values. If not defined, the cron will run on every hour.

Day

day (num or str): The day defines the day values you would like the cron to run on. Values may be defined in the same way as minute values. If not defined, the cron will run every day. In addition, week values may be defined with days as specified below.

Week Examples:

  • 'w1' - cron will run every sunday
  • 'w1-w4' - cron will run sunday through wednesday
  • 'w4,w6' - cron will run wednesday and saturday

Month

month (num or str): The month defines the month values you would like the cron to run on. Values may be defined in the same way as minute values. If not defined, the cron will run every month. Months start as 1 = January and 12 = December

timebot.set({
    path:'first',
    minute:1
    day:'11-14,w4',
    month:'3-7'
},{
    cron:function(D){
        //do cool stuff
        console.log('cron ran successfully!');
    }
});

/*
The above cron will run on the first minute of each hour 
on the 11th through 14th day of each month 
and any wednesdays 
in the months of March through July
*/

Callbacks

Cron

cron (fun): Callback that is triggered when the cron is run. Receives one argument that is the Date object for the current time.

Cancelling Crons

timebot.clear({
    path:'first'
});

/*
This will cancel the cron defined above
*/

Moar

Timebot is setup to perform tasks in increments of minutes, future versions may support other increments.

npm loves you