This documentation is for WSO2 Application Server 5.2.0. View documentation for the latest release.
Adding Scheduled Tasks - Application Server 5.2.0 - WSO2 Documentation
Skip to end of metadata
Go to start of metadata

Using the WSO2 Data Services Server, a task can be scheduled to execute periodically and also only a limited number of times. Follow the steps below to schedule a task.

1. Log on to the Data Services Server Management Console and select "Data Services -> Scheduled Tasks" in the "Main" menu.

2. The "Scheduled Tasks" page opens. Click the "Add New Task" link.

3. Fill the required information.

Tasks can be configured to invoke a data-service operation or to use a custom java class which implements the "org.wso2.carbon.dataservices.task.DataTask" interface. The following set of properties should be defined in order to successfully create a task. 

  • 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 at the moment the it is scheduled.
Parameters required to define 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.
Parameters required to define a task that uses a custom java class
  • Data Service Task Class : Name of the java class which has implemented "org.wso2.carbon.dataservices.task.DataTask" interface. The definition of the interface is follows:
package org.wso2.carbon.dataservices.task;
* This interface represents a scheduled data task.
  public interface DataTask {
      void execute(DataTaskContext ctx);

The following code snippet shows a sample DataTask implemenation:

package samples;
import java.util.HashMap;
import java.util.Map;
import org.wso2.carbon.dataservices.core.DataServiceFault;
import org.wso2.carbon.dataservices.core.engine.ParamValue;
import org.wso2.carbon.dataservices.task.DataTask;
import org.wso2.carbon.dataservices.task.DataTaskContext;

public class SampleDataTask implements DataTask {    
   public void execute(DataTaskContext ctx) {
       Map<String, ParamValue> params = new HashMap<String, ParamValue>();
       params.put("increment", new ParamValue("1000"));
       params.put("employeeNumber", new ParamValue("1002"));
       try {
           ctx.invokeOperation("RDBMSSample", "incrementEmployeeSalary", params);
       } catch (DataServiceFault e) {
         // handle exception

4. After configuring the task with appropriate values, click the "Schedule" button to complete.

  • No labels