Scheduler Service
Canvas provides an independently working ancillary service called Scheduler where you can program any job to execute automatically at scheduled intervals by invoking the scheduler service. For example, you can configure the scheduler to carry out a task like fetching alerts from staging area and delivering those to the recipients at a given time.
To schedule a job, you have to hit the scheduler endpoint with appropriate payload with URL or service endpoint that you want to invoke from the scheduler and then specify the scheduling details such as job group, job name, cronexpression etc.
A cronexpression is a 6 or 7-digit expression that represents a schedule. It takes the following format and you can schedule any job by specifying this expression accordingly in the payload.
Refer the following link to generate your cronexpression.
For example,
Example | Description |
---|---|
0 0 0 * * * | Indicates a daily schedule. |
0 0 12 * * ? | Indicates a daily 12 PM schedule. |
0 15 10 * * ? 2019 | Indicates a daily 10:15 AM schedule in the year 2019. |
Sample URLs for GET and POST calls:
The URLs to create a job and fetch details of a job are as follows:
To create a job: Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â http://localhost:8080/CTScheduler/rest/schedule/subscribe Â
To fetch job and its details: Â Â Â Â Â Â Â Â http://localhost:8080/CTScheduler/rest/schedule/getjob
Sample payload to create a job with two triggers:
Refer the following sample payload to create a job using scheduler. The sample job invokes the Google website ÂÂÂÂevery two hours and every minute through two triggers respectively.
Note: You can create any number of jobs to be scheduled by specifying the job list with the respective schedule time one below the other in the payload.
{ Â "jobgroup": "Google", Â "jobname": "InvokeGoogle", Â "callbackdetail": Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â "endpoint": "http://www.google.com", Â Â Â Â Â Â Â Â Â Â "servicetype": "GET", Â Â Â Â Â Â Â Â Â Â Â "payload": "{}" Â Â Â Â Â }, Â "trigger": Â Â Â Â [{ Â Â Â Â Â Â Â Â Â Â "triggergroup": "trigger1", Â Â Â Â Â Â Â Â Â Â "triggername": "triggername1", Â Â Â Â Â Â Â Â Â Â Â "cronexpression": "0 */2 * ? * *" Â Â Â Â }, Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â "triggergroup": "trigger2", Â Â Â Â Â Â Â Â Â Â Â "triggername": "triggername2", Â Â Â Â Â Â Â Â Â Â Â "cronexpression": "0 0 * ? * *" Â Â Â Â Â }] }
In the sample payload,
Key | Description |
---|---|
jobgroup | Specify the user-defined job category. |
jobname | Specify the user-defined job name. |
endpoint | Enter the URL or service endpoint to be invoked. |
servicetype | Specify the service type; GET/POST. |
payload | Pass the request data if required. |
triggergroup | Specify the user-defined trigger group for the specific schedule. |
triggername | Specify the user-defined trigger name for the specific schedule. |
cronexpression | Enter the 6-digit string to represent your schedule. |