com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Scheduling Tasks

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 the getProductQuantity operation and set an event to send an email if the quantity goes down to some level.

Task handling in a clustered environment

In a clustered environment, tasks are distributed among server nodes according to the round-robin method, by default. If required, you can change this default task handling behaviour as explained here.

Also, note that a scheduled task will only run in one of the nodes (at a given time) in a clustered environment. The task will failover to another node, only if the first node fails.

Adding Scheduled Tasks

Follow the steps given below to schedule a task.

  1. Log in to the management console and click Data Services > Scheduled Tasks in the Main menu. The Scheduled Tasks window opens. 
  2. Click Add New Task to open the New Scheduled Task screen.
  3. Enter a name for the task in the Task Name field.

  4. 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. 
  5. 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 org.wso2.carbon.dataservices.task.DataTask interface.

  6. To successfully create a task, provide the following set of properties:

    • If the scheduling type is DataService Operation, the following fields should be used:

      1. Data Service Name: Name of the relevant data service.
      2. 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.DataTask interface in the DataService Task Class field.

      The definition of the interface is as 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 implementation:

      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 {    
         @Override    
         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
             }
          }
      } 
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.