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