The introduction

Recently, The open source micro-service TASK scheduling platform siA-Task of Credit Ease is a distributed TASK scheduling platform. Sia-task is simple and convenient to use and easy to start with. After the TASK scheduling platform is deployed and built, the whole scheduling process can be realized by writing tasks and configuring jobs. This article creates an example of a JOB that is associated with two cascaded tasks, TASKONE(front TASK) and TASKTWO(rear TASK). It mainly describes how a JOB is associated with two cascaded tasks and how the JOB is scheduled using sia-Task. The result is a call to two TASK actuators.

Develop reading: appropriate letter open source | appropriate letter open source micro service SIA – TASK scheduling platform

Appropriate letter open source | distributed TASK scheduling platform SIA – TASK of architectural design and run the process

First, build the task scheduling platform according to the deployment document.

Source code address: github.com/siaorg/sia-…

Official documentation: github.com/siaorg/sia-…

The TASK scheduling platform is mainly composed of TASK scheduling center, TASK scheduling center and third-party services such as ZK and DB. The main tasks required for building siA-Task scheduling platform include:

1. Build MySQL and build tables according to the construction of tables

2. They are installed

3. Package and deploy front-end siA-Task projects

4. Task Orchestration Center (SIa-task-config) deployment

5. The task scheduling center (SIa-task-Scheduler) is deployed

After you clone the code repository from Github and download the source code, you can set up and start the SIA-Task TASK scheduling platform according to the SIA-Task deployment guide. For details, see the SiA-Task Deployment Guide

After setting up the SIa-Task TASK scheduling platform, the next step is to write the TASK execution instance.

Second, write and start the TASK executor instance according to the development document.

According to the SIA-Task development guide, two TASK examples, TASKONE(front TASK) and TASKTWO(rear TASK), are written. For specific development rules, see the SIA-Task Development Guide. The key configuration of the TASK example, namely the code, is shown and introduced in detail in the following sections.

This example is a Springboot project, and the key dependency package sia-task-Hunter of siA-Task is introduced through POM files to realize automatic fetching of TASK actuators. The sia-task-hunter package in the sia-Task source code needs to be installed as a jar package using MVN install command. The sia-task-Hunter package in the SIa-Task source code is shown in the following figure:

Then you can write examples, examples mainly include the following parts:

configurationPOMFile critical dependency

          <! -- Add personalization dependency (sia-task-hunter) -->
          <dependency>
            <groupId>com.sia</groupId>
            <artifactId>sia-task-hunter</artifactId>
            <version>1.0.0</version>
          </dependency>
Copy the code

Configuration file Main configuration items

  # Project name (required)
  spring.application.name: onlinetask-demo
  
  # Application port number (required)
  server.port: 10086
  
  # zookeeper address (mandatory)
  zooKeeperHosts: *. *. *. * : 2181, *. *. *. * : 2181, *. *. *. * : 2181
  
  # Whether to enable AOP aspect (default true)
  spring.aop.auto: true
  
  # Whether to enable @onlinetask serial control (AOP functionality must be enabled if used) (default true) (Optional)
  spring.onlinetask.serial: true
Copy the code

Write the main code for the TASK executor

@Controller
public class OpenTestController {

    @OnlineTask(description = "Success, no entry",enableSerial=true)
    @RequestMapping(value = "/success-noparam", method = { RequestMethod.POST }, produces = "application/json; charset=UTF-8")
    @CrossOrigin(methods = { RequestMethod.POST }, origins = "*")
    @ResponseBody
    public String taskOne(a) {
        Map<String, String> info = new HashMap<String, String>();
        info.put("result"."success-noparam");
        info.put("status"."success");
        System.out.println("Calling taskOne task succeeded");

        return JSONHelper.toString(info);
    }

    @OnlineTask(description = "Success, with input",enableSerial=true)
    @RequestMapping(value = "/success-param", method = { RequestMethod.POST }, produces = "application/json; charset=UTF-8")
    @CrossOrigin(methods = { RequestMethod.POST }, origins = "*")
    @ResponseBody
    public String taskTwo(@RequestBody String json) {
        Map<String, String> info = new HashMap<String, String>();
        info.put("result"."success-param"+"The entry is:"+json);
        info.put("status"."success");
        System.out.println("Calling taskTwo task successfully");

        returnJSONHelper.toString(info); }}Copy the code

After writing the TASK executor instance, start the process in which the executor resides

The startup log is shown below:

The log indicates that the process is started and the TASK executor information is uploaded to the ZK.

Observe the TASK management interface, as shown in the following figure:

You can see from the figure that tasks have been synchronized to the database.

Thirdly, you need to create jobs and associate and configure tasks with jobs.

Perform the following operations according to the user guide.

Create a JOB and set parameters

On the JOB management page, click Add JOB

Tap to enter the Page for adding a Job

Select Job_Group and the name of the Group to which the TASK to be associated belongs.

Set the Job type and other items respectively. You can also set the Job type to FixRate(specific point in time). In this example, the Job type is CRON. Is executed every 30 seconds from the current time

Click Add. The JOB is added successfully.

Configure the TASK

After a JOB is added, you need to configure one or more tasks for the JOB. This example uses two cascading tasks as an example.

Click Configure TASK to enter the TASK information configuration page.

As shown in the figure above, pull the two tasks to be configured to the right and click edit button (pencil shape) to enter the TASK parameter configuration interface.

TASKONE Parameter Settings:

TASKTWO parameter configuration:

Click Add to add TASKONE and TASKTWO to the JOB.

After the addition, the dependency of two tasks can be configured, as shown in the following figure:

Use the arrow to point TASKONE(front-facing TASK) to TASKTWO(post-facing TASK) to set the dependency relationship between tasks. Click Submit to complete the JOB configuration. After the JOB configuration is complete, click TASK to view the TASK configuration details of the JOB.

TASK configuration information graph

TASK Configuration details

Finally, activate the JOB and observe the corresponding logs.

After the TASK is successfully configured, click the Activate button in the status operation drop-down button to activate the JOB.

After the JOB is activated, refresh the page. The scheduler IP address and port number are displayed in the red box on the JOB list scheduler, indicating that the activated JOB is preempted by the scheduler.

Observe JOB and TASK logs on the management interface

After the JOB is activated, the page for scheduling logs is displayed. After the JOB execution time is displayed, the JOB execution logs are displayed, as shown in the following figure.

Label 1: indicates the JOB log.

Label 2: indicates the TASK(TASKONE) logs associated with the JOB.

Label 3: indicates the post-task (TASKTWO) logs associated with the JOB.

4: endTask Indicates a virtual TASK added to the system. It indicates that only one TASK of the JOB is scheduled.

At the same time, it can also be observed from the execution time, which is scheduled every 30 seconds.

Then observe the execution TASK instance logs

You can also observe the executor instance TASK log to verify that the call is successful.

From the logs, we know that the call did succeed, and it was called every 30 seconds.

Stop the JOB

To stop a JOB, click the Stop button in the Status operation drop-down list to stop the JOB.

This paper is only a preliminary practical use of the micro-service TASK scheduling platform SIA-Task. Through the above description, it can realize the TASK scheduling function of siA-Task to the execution instance TASK. The example set up in this paper is very simple, suitable for quickly starting with SIA-Task, of course, Sia-task also has more powerful TASK scheduling functions to cope with more complex business scenarios. You can continue to use siA-Task in depth and combine its function points with services to apply it to more complex business scenarios.