Task scheduling is used to invoke a data service operation periodically or for a specified number of times. The scheduling functionality is useful when a specific data service operation scheduled for execution is associated with an event-trigger. When such a scheduled task is run, the event can be automatically fired by evaluating the event trigger criteria. For example, we can schedule a task on
getProductQuantity operation and set an event to send an email if the quantity goes down to some level.
The following topics are covered:
Configuring server for task handling
For instructions on how to configure the Task Scheduling component for you server, see the admin guide.
Adding Scheduled Tasks
Follow the steps given below to schedule a task.
- Log in to the management console and click Data Services > Scheduled Tasks in the Main menu. The Scheduled Tasks window opens.
- Click Add New Task to open the New Scheduled Task screen.
Enter a name for the task in the Task Name field.
Specify how the task should be triggered using the following fields:
- Task Repeat Count : Number of cycles to be executed. If you enter 0, the task will execute once. If you enter 1, the task will execute twice and so on.
- Task Interval : Time gap between two consecutive task executions
- Start Time : Starting time of the scheduled task. If this is not given, the task will start as soon as it is scheduled.
Select one of the following values for the Scheduling Type field:
DataService Operation: If this option is selected, the task will be invoking a data service operation.
DataService Task Class: If this option is selected, the task will be using a custom class that implements the
To successfully create a task, provide the following set of properties:
If the scheduling type is DataService Operation, the following fields should be used:
- Data Service Name: Name of the relevant data service.
Operation Name: Data service operation to be executed from the task.
Note that only data services with HTTP endpoints are available when scheduling tasks to invoke data service operations. Also, you can use only operations with no input parameters when scheduling.
If the scheduling type is DataService Task Class, you must specify the Java class that implements the
org.wso2.carbon.dataservices.task.DataTaskinterface in the DataService Task Class field.
The definition of the interface is as follows:
The following code snippet shows a sample DataTask implementation: