– When a job needs to be executed periodically we need the help of Scheduler plugin.
– Using this plugin we can set a schedule for execution of a job in our Servoy application.
– We can set the start and end time of the job, the duration or gap of the execution of the job and the number of times the job is to be executed.
– Lets check the methods of the Scheduler plugin :-
By using this method we can add a schedule/Job with our application.
It takes the following parameters.
jobname (String) – Name of the job.
startDate (datetime) – From which date and time the job will start its execution.
globalMethod – Name of the global method to be executed to perform the job.
repeatInterval (number) – We can specify the time interval in miliseconds for the next execution of the job. (optional)
repeatCount (number) – number of times the job is to be executed. (optional)
endDate (datetime) – When the repetation of the job needs to be stoped.
arguments (Object) – When our global method needs some arguments for execution we need to pass it through this object Array. (Optional)
To run a job in every 3seconds from now indefinitely.
plugins.scheduler.addJob(‘My_job’, new Date(), globals.jobName, 3000);
We can check the name of the last run job.
var last_job_name = plugins.scheduler.getLastRunJobName()
It returns the name of the current jobs as a string Array.
var current_jobs = plugins.scheduler.getCurrentJobNames()
It takes the Job name as parameter and removes the job.
The addJob() method starts at regular interval, say in every 1 minutes or 2 minutes.
But the addCronJob() gives flexibility to set the date, time, weekdays , month, etc. for the job.
The term “cron” means to execute a job periodically.
jobname (String) – Name of the job
cronTimings (string) – The specific format in which the job will be executed.
globalMethod – Name of the global method to be executed.
startDate (datetime) – From which datetime the job will start its execution. (optional)
endDate (datetime) – When the repetation of the job needs to be stoped. (optional)
arguments (Object) – When your global method needs some arguments for execution. (Optional)
The most important parameter in addCronJob() is the cronTimings.
It takes 6 items/informations together to build the cronTiming format.
d. Day of Month.
f. Day of Week
plugins.scheduler.addCronJob(‘My_job’, ‘0 0 13 ? * MON,WED,FRI’, globals.jobName)
‘0 0 13 ? * MON,WED,FRI’ = For every Monday, Wednesday and Friday at 1PM of every month.
? : No specific Value
* : Every possible value
Months are represented by JAN,FEB,MAR…. or 0,1,2,… respectively.
Days are represented by SUN,MON,TUE,….. or 1,2,3,…. respectively.
For more information on cron timings format please refer
Uses of Scheduler plugin:
– Refreshing the current time or uptime of the application in every seconds.
– Refreshing the form automatically in a particular time period.
– Checking for the active/ inactive clients at regular interval and taking action accordingly.
– Performing backup or commiting data regularly, etc.