My Experiments with SAP Cloud Platform Workflow, FaaS and Twilio – Part 3 Demystifying Cron Expressions
All blogs in the series
|1||Setting up the workflow|
|2||Function as a service|
|4||Integrating the Twilio|
What we are going to make?
In our previous blog we have been able to successfully create a serverless function which basically is able to fetch the workflows triggered via an API call. Now we would like a job to be scheduled once a day which will send the consolidated list of workflows trigger to the workflow administrator. SAP help has provided us with a trigger type Timer which shall be used to accomplish our scheduling objective. It uses some kind of cron expressions for the scheduling so let’s first understand what are these cron expressions?
Demystifying Cron Expressions
Like in our ABAP we do the job scheduling via SM36, on a similar line cron is a scheduler for tasks and is basically available on unix based systems. Very high chance our ABAP job scheduling using cron in the background .
Like in ABAP job scheduling we specify the interval time etc. when the task will be run, in same way cron uses a concept of Cron Expressions. The jobs frequency etc. is decided by the cron expressions. For example the cron expression for a job which shall be triggered every second
* * * * * ? *
If you note it has 7 fields out of which last one is optional.Let us now have quick look into these 7 fields. On a higher level these fields represent different unit of time as shown below.
You must be wondering what these L,C,* etc. characters are? Read this blog to understand in detail what these special characters do. For example ‘*’ is used for all time, for example if i maintain * in minute place then it means every minute task has to be executed . L if we use in Day-Month then it means Last day of the month, we can also use L-1, L-2 to denote second last, third last day. In relation to day week it for example 1L means last sunday. If we use */15 in seconds we expect the job to run at 15,30,45,60 seconds.
Creating Our cron trigger for our function
Now since we understand what Cron expressions are, let us create a cron expression to run every minute.While adding the trigger for our serverless functions we noted for some reason it does not run for every second if scheduled , by default it starts from minutes. I tweeted about this issue and we had a nice blog from Former Member on how to create a trigger. Since it starts by default by minutes to so our cron expression used is “* * * * *” .
We now have a serverless function being called at regular interval fetching the triggered workflows detail as shown below.
What is next
Since now we have our workflow with forms to trigger a workflow, a serverless function scheduled to run at regular interval, all that is left is to share this detail via twilio to desired recipients which we will cover in next part. Feel free to share your feedback.