The scheduler plugin enables the creation and management of background jobs in headless clients. It supports both cron-based schedules and custom intervals, allowing for versatile task automation.
The addCronJob method schedules tasks using cron expressions, with options for specifying start and end dates, and passing arguments. This method is ideal for periodic tasks such as running jobs at specific times or intervals.
For more custom scheduling, the addJob method allows tasks to be scheduled at a specific start date with options for repetition intervals, counts, and end dates. Additional arguments can be passed to provide further flexibility in task execution.
To monitor jobs, the getCurrentJobNames method retrieves active jobs, and getLastRunJobName provides the most recently executed job. The removeJob method simplifies job management by enabling the deletion of specific tasks.
For more information, refer to the section of the documentation.
Methods Summarized
Type
Name
Summary
void
Adds a cron job to the scheduler.
void
Adds a cron job to the scheduler.
void
Adds a cron job to the scheduler.
void
Adds a cron job to the scheduler.
void
Adds a job to the scheduler.
void
Adds a job to the scheduler.
void
Adds a job to the scheduler.
void
Adds a job to the scheduler.
void
Adds a job to the scheduler.
void
Adds a job to the scheduler.
Returns an array with the current jobs.
Returns the last job run from the scheduler.
Removes a job from the scheduler.
Methods Detailed
addCronJob(jobname, cronTimings, method)
Adds a cron job to the scheduler. A cron job must have at least one minute between each execution (otherwise it won't execute).
Parameters
Returns: void
Sample
// see: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html for more info
// add a job that runs every 20 minutes after the hour (0,20,40)
plugins.scheduler.addCronJob('20mins','0 0/20 * * * ?',method)
// add a job that runs every day at 23:30 between now and 5 days from now
var dateNow = new Date();
var date5Days = new Date(dateNow.getTime()+5*24*60*60*1000);
plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',method,dateNow,date5Days)
Adds a cron job to the scheduler. A cron job must have at least one minute between each execution (otherwise it won't execute).
Parameters
Returns: void
Sample
// see: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html for more info
// add a job that runs every 20 minutes after the hour (0,20,40)
plugins.scheduler.addCronJob('20mins','0 0/20 * * * ?',method)
// add a job that runs every day at 23:30 between now and 5 days from now
var dateNow = new Date();
var date5Days = new Date(dateNow.getTime()+5*24*60*60*1000);
plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',method,dateNow,date5Days)
Adds a cron job to the scheduler. A cron job must have at least one minute between each execution (otherwise it won't execute).
Parameters
Returns: void
Sample
// see: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html for more info
// add a job that runs every 20 minutes after the hour (0,20,40)
plugins.scheduler.addCronJob('20mins','0 0/20 * * * ?',method)
// add a job that runs every day at 23:30 between now and 5 days from now
var dateNow = new Date();
var date5Days = new Date(dateNow.getTime()+5*24*60*60*1000);
plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',method,dateNow,date5Days)
Adds a cron job to the scheduler. A cron job must have at least one minute between each execution (otherwise it won't execute).
Parameters
Returns: void
Sample
// see: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html for more info
// add a job that runs every 20 minutes after the hour (0,20,40)
plugins.scheduler.addCronJob('20mins','0 0/20 * * * ?',method)
// add a job that runs every day at 23:30 between now and 5 days from now
var dateNow = new Date();
var date5Days = new Date(dateNow.getTime()+5*24*60*60*1000);
plugins.scheduler.addCronJob('23:30','0 30 23 ? * *',method,dateNow,date5Days)
addJob(jobname, startDate, method)
Adds a job to the scheduler.
Parameters
Returns: void
Sample
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
addJob(jobname, startDate, method, arguments)
Adds a job to the scheduler.
Parameters
Returns: void
Sample
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+20000);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob('in20seconds',startDate,method,20000,40,endDate)
getCurrentJobNames()
Returns an array with the current jobs.
Sample
plugins.scheduler.getCurrentJobNames()
getLastRunJobName()
Returns the last job run from the scheduler.
Sample
plugins.scheduler.getLastRunJobName();
removeJob(jobname)
Removes a job from the scheduler.
Parameters
Sample
// removes a job 'myjob' from the scheduler
plugins.scheduler.removeJob('myjob');
jobname ;
cronTimings ;
method ;
jobname ;
cronTimings ;
method ;
startDate ;
jobname ;
cronTimings ;
method ;
startDate ;
endDate ;
jobname ;
cronTimings ;
method ;
startDate ;
endDate ;
arguments ;
jobname ;
startDate ;
method ;
jobname ;
startDate ;
method ;
repeatInterval ms
jobname ;
startDate ;
method ;
repeatInterval ms
repeatCount ;
jobName ;
startDate ;
method ;
repeatInterval ms
repeatCount ;
endDate ;
jobname ;
startDate ;
method ;
repeatInterval ms
repeatCount ;
endDate ;
arguments ;
jobname ;
startDate ;
method ;
arguments ;
Returns: an array of job names currently scheduled for the client.
Returns: the name of the last job that was run by the scheduler.
jobname ;
Returns: true if the job was successfully removed; false otherwise.