Scheduled tasks (NL: Geplande taken)
Certain components may require a scheduled automated process, e.g. to process some data at 5:00 in the evening or check every 30 minutes if it can send an email with updates. For this, a scheduling service is required via the WebService. The functionality of this is almost similar to e.g. a cron job, you have to make a schedule and every minute the scheduling service will check his schedule whether to execute a process in the component.
First, you need to know how your process is called that you want to execute via the scheduling service. This process needs to be a process component. In the Architect, look for its internal name. e.g. send_email_to_customers. Secondly, as you will probably use this component in an integrated model, go to the folder containing your application, and browse to \App_Code\generated\controller\ and look for a .cs file that has the same internal name as your process. E.g. send_email_to_customersControllerComponent_1666434.cs. Copy the send_email_to_customersControllerComponent_1666434 part in your clipboard.
Hint: in an integrated model, the unique identifier (so the number) is different than in your component.
Summary of the steps below:
To create a scheduled task, you must first identify the process that you want to execute and create a “process action definition” in the settings of your application. You can then create a scheduled task and link it to the process, defining the schedule for the task. You must then register the task with the scheduling service to activate it. The task will be executed according to the schedule that you have defined.
Steps
-
Go to settings of your application
-
Find ‘process action definitions’.
-
Create a new one.
-
In the dropdown, choose the process of your choice. For example, “sales_price_list_items_set_all_prices_to_currentcontrollercomponent_2460130” It takes a while for the content to load, so be patient. After that, click on save.
-
Click the button to (re)load parameters and return value. If the process has any, they will appear in the grids below.
You have now successfully created a process call. It can be used in workflows or scheduled tasks.
-
We will now create a scheduled task and use the new “process action definition”. Go to the settings and search for “scheduled tasks”.
-
Add a new scheduled task. Give it a description that explains what the task is doing and why and when it should be running.
-
Save the scheduled task.
-
Now we need to define which ‘process’ (process action definition) will be executed and when. First, define the process by clicking on the row “Process” in the grid “Task arguments”.
-
Chose the parameter ‘process’. The value(process) will be the ‘process action definition’ that you created in step 5.
-
Click on save. Also click on ‘Update parameters’ to retrieve any parameters that might exist (see step 6). If the process has required parameters, you need to fill them in. If it hasn’t any, you can go to the next step.
-
The scheduled task is now linked to a process. But the application still doesn’t know WHEN it should be executed. Therefore, we need to create a ‘Schedule’.
-
Add a schedule if the grid is empty:
-
Edit the values to define when the tasks should be executed. For example, like this.
Whenever the clock shows a time when the minute counter is equal to “XX:15” it will be executed. So once an hour. * simply means that any value is valid. So in the example above the hours, day of month and month do not matter.
-
The following example tells the scheduler to execute the task at any time when the minutes are divisible by “15”. You could alternatively write “0,15,30,45” to make it more readable.
-
The final step is to tell the scheduling service that we created a new task that we want to execute regularly by registering it. Click on ‘Register’
-
If the scheduler is set up correctly, it will look like this. If not, go to KB858 and set up the scheduling service properly. Or read this post: How to configure queues for scheduling service - #3 by Helena
-
Test if everything works correctly by clicking on “Run now”. This will execute the process that you have defined. In the example, all prices will be updated.