Alex-Werner / hapi-cron-job

Cron/Schedule jobs for Hapi framework
MIT License
5 stars 8 forks source link
cron-jobs hapi hapi-plugin parse plugins

hapi-cron-job

cron_jobs

Overview

hapi-cron-job, is a plugin for hapi that will allows you to execute cron job at a specified time (eg: every 2 hour, at 8:00 pm, every monday at 11:00 am, every first day of the month).

Installation

Using npm:

npm install hapi-cron-job

How to:

See pratical example

var displayTime = function(){
    var ymd = new Date().toISOString().slice(0,new Date().toISOString().indexOf("T"));
    var hms = new Date().toISOString().substr(11, 8);
    console.log(ymd+" "+hms);
};
var callback = function(enabledJobs){
    //Do something with enabledJobs
}
var enabledCallback = function(job, scheduleParsed){
    //Do something with job and scheduleParsed
}
Server.register({
    register:require('hapi-cron-job'),
    options:{
        jobs:[
             {
                name:"diplay time",
                enabled:true,
                enabledCallback:enabledCallback,//Executed at end of import of the job, just before immediate Callback
                immediate:true,//Will execute function on starting
                schedule:"every 1 s",
                execute:displayTime,
                environments:['development','staging']//using env (process.env.NODE_ENV)
             }
        ],
        callback:callback//Executed at end of process and return enabledJobs
    }
},function(err){
     if(err){throw err;}
 });

Options

Allowed schedule

You can specify any schedule format that look like :

Mind that every X PERIOD, is absolute, if you started your server at 10:44 pm and set to every 1 h, it will be executed at 11:44pm, 0:44am and so on...
You can have your cron executed at the next plain hour and every next hour then.

Use every plain hour for that. (eg:If started at 3:46, next exec will be 4:00 then 5:00...)
Same can be done with minutes with every plain minute (eg: Started at 3:46, next exec will be 3:50,4:00,..)

Definitions

Next :

About you

If this can help even one person, I would be hapi enough (see what I did here ? :D).
I will work on that project till I will be confident enought that it will answer perfectly to the need to at least one person.
If you are that person, please, do not hesitate to :

You could also drop me a word on twitter : @obusco.

I would like to have any feedback that you use it, may be even for what and how I could help improving this package to fit your needs.

About stuff

Versioning

Releases will be numbered with the following format (semver):

<major>.<minor>.<patch>

The reason we doing that, is that, far from marketing or stuff. You will know easily if a breaking change occurs by just looking the first number. Mind that some major version (breaking changes) can be absolutely necessary (bugfix). But at least it won't break your code

Contributors

I want to take time to thank :

Much love to you ! <3

Inspired by