The task orchestration feature of Data Management (DMS) is used to orchestrate and schedule tasks. You can create a task flow composed of one or more task nodes to implement complex scheduling and improve data development efficiency.

Prerequisites

A database is created, and you have the change permissions on the database. For more information about how to apply for permissions, see Overview.

Background information

During sales promotions, e-commerce companies often give discounts to their customers. For example, when the cumulative purchase amount of a user reaches a certain value, the e-commerce company issues a coupon with a certain discount to the user so that the user can purchase a service or product at a lower price. This topic describes how to use the task orchestration feature to create a task flow composed of the SQL Assignment for Single Instance, Conditional Branch, and Single Instance SQL nodes to implement coupon issuance in the database.

Procedure

  1. Create a configuration table, a business table, and a coupon issuance table and insert data into the tables. For more information, see Prepare the environment.
  2. Create a task flow.
    1. Log on to the DMS console V5.0.
    2. In the top navigation bar, click DTS. In the left-side navigation pane, choose Data Development > Task Orchestration.
    3. Click Create Task Flow.
    4. In the Create Task Flow dialog box, set Task Flow Name and Description and click OK.
  3. Orchestrate task nodes.
    1. In the Task Type list on the left side of the canvas, drag the SQL Assignment for Single Instance, Conditional Branch, and Single Instance SQL nodes to the blank area on the canvas.
    2. Connect the nodes to form a task flow.

      Move the pointer over the SQL Assignment for Single Instance node, click the hollow circle on the left side of the SQL Assignment for Single Instance node, and then draw a line to connect to the Conditional Branch node.

      Move the pointer over the Conditional Branch node, click the hollow circle on the left side of the Conditional Branch node, and then draw a line to connect to the Single Instance SQL node.

  4. Configure the task nodes.
    1. Click the SQL Assignment for Single Instance node and configure it. For more information, see Configure an SQL assignment node.
      The following figure shows the configured output variables.
      Enter the following SQL statement:
      select * from activity_setting limit 1
    2. Click the Conditional Branch node and configure it. For more information, see Configure a conditional branch node.
      The following figure shows the configured conditional expression.Conditional expression
    3. Click the Single Instance SQL node and configure it.
      Enter the following SQL statement:
      INSERT INTO `voucher_send_list`(`user_id`,`consumption_sum`,`quota`)
      SELECT * FROM
      (SELECT `user_id`, sum(count) AS consumption_sum,${Quota} FROM `consumption_records`
       WHERE `time` > '${bizdate}'  GROUP BY `user_id`) t
      where `consumption_sum`>${ConsumptionLimit}
  5. Click Try Run in the upper-left corner of the canvas to test the task flow.
    You can view the voucher_send_list table in the SQL console. The coupon data is inserted into the table. Coupon issuance result
  6. Optional:Enable scheduling for the task flow.
    1. Click the blank area on the canvas.
    2. Click the Task Flow Information tab.
    3. In the Scheduling Settings section, turn on Enable Scheduling. For more information, see Configure a task flow.
  7. Publish the task flow. After the task flow is published, it is automatically run based on the specified scheduling cycle.
    1. Click Publish in the upper-left corner of the canvas.
    2. In the Publish dialog box, enter text in the Remarks field and click OK.

Prepare the environment

  1. Log on to the DMS console V5.0.
  2. In the top navigation bar, choose SQL Console > SQL Console.
  3. In the Please select the database first dialog box, enter a keyword to search for a database, select the database from the search results, and then click Confirm.
  4. Create a configuration table, a business table, and a coupon issuance table.
    1. Create a configuration table named activity_setting. Copy and paste the following SQL statement to the SQL editor and click Execute.
      Use the following SQL statement to create the table:
      CREATE TABLE `activity_setting` (
          `has_promotion` tinyint(1) NOT NULL COMMENT 'Whether discounts are provided',
          `consumption_limit` int(11) NOT NULL COMMENT 'Purchase amount limit',
          `quota` int(11) NOT NULL COMMENT 'Coupon discount',
          PRIMARY KEY (`has_promotion`)
      ) ENGINE=InnoDB
      DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
      ROW_FORMAT=COMPACT
      AVG_ROW_LENGTH=16384;
    2. Create a business table named consumption_records. Copy and paste the following SQL statement to the SQL editor and click Execute.
      Use the following SQL statement to create the table:
      CREATE TABLE `consumption_records` (
          `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Record ID',
          `time` datetime NOT NULL COMMENT 'Purchase time',
          `count` int(11) NOT NULL COMMENT 'Purchase amount',
          `user_id` bigint(20) NOT NULL COMMENT 'User ID',
          PRIMARY KEY (`id`)
      ) ENGINE=InnoDB
      DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
      COMMENT='Purchase record table'
      AUTO_INCREMENT=8001
      ROW_FORMAT=COMPACT
      AVG_ROW_LENGTH=54;
    3. Create a coupon issuance table named voucher_send_list. Copy and paste the following SQL statement to the SQL editor and click Execute.
      Use the following SQL statement to create the table:
      CREATE TABLE `voucher_send_list` (
          `Id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Record ID',
          `user_id` int(11) NULL COMMENT 'User ID',
          `consumption_sum` int(11) NULL COMMENT 'Purchase amount',
          `quota` int(11) NULL COMMENT 'Coupon discount',
          PRIMARY KEY (`Id`)
      ) ENGINE=InnoDB
      DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
      AUTO_INCREMENT=1
      ROW_FORMAT=COMPACT
      AVG_ROW_LENGTH=0;
  5. Insert data into the configuration table. Copy and paste the following SQL statement to the SQL editor and click Execute.
    Use the following SQL statement to insert data into the table:
    INSERT INTO activity_setting( has_promotion, consumption_limit, quota)
    VALUES('1','100','30');
  6. Insert data into the business table. Use the test data generation feature of DMS to generate test data. For more information, see Generate test data.
    The following figure shows an example on how to generate data for the consumption_records table.
    Generate data