Task scheduling is used to invoke a data service operation periodically or for a specified number of times. Read about data services and operations. 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.
Task scheduling functionality is provided by the following feature in the WSO2 feature repository:
Name : Data Service Tasks Feature
Identifier : org.wso2.carbon.dataservices.task.feature.group
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 in the WSO2 Carbon documentation.
Adding Scheduled Tasks
Follow the steps given below to schedule a task.
- Log in to the management console of the Data Services Server and select Data Services > Scheduled Tasks in the Main menu.
- The Scheduled Tasks window opens. Click Add New Task. Fill the required information.
You can configure a task to invoke a data service operation or to use a custom Java class that implements the
org.wso2.carbon.dataservices.task.DataTaskinterface. To successfully create a task, provide the following set of properties:
- Task Name : Name of the scheduled task
- 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.
Parameters required for defining a task that uses a data service operation:
- 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.
Parameters required for defining a task that uses a custom java class:
Data Service Task Class : Name of the java class that implements
org.wso2.carbon.dataservices.task.DataTaskinterface. The definition of the interface is as follows:
The following code snippet shows a sample DataTask implementation: