Yixin Open Source | Microservice Task Scheduling Platform SIA-TASK


Recently, Yixin Open Source Microservice TASK Scheduling Platform SIA-TASK, SIA-TASK belongs to a distributed task scheduling platform. It is simple and convenient to use and easy to start. After the SIA-TASK task scheduling platform is deployed and built, the JOB is configured to schedule after task is written, thus realizing the whole scheduling process. In this paper, a new JOB example is created. The JOB is associated with two tandem TASKs, TASK One (front TASK) and TASKTWO (rear TASK). It mainly expounds how a JOB configures two tandem tasks in association and how the JOB implements task scheduling through SIA-TASK, and finally realizes the call to the two task actuators.

Expand reading:Yixin Open Source | Yixin Open Source Microservice Task Scheduling Platform SIA—TASK

Architecture Design and Operation Process of Yixin Open Source | Distributed Task Scheduling Platform SIA-TASK

First of all, according to the deployment documents to build a task scheduling platform.

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

Official documents:https://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 task scheduling platform include:

1.MySQL Construction and Table Construction Based on Table Construction Statements

2.zookeeper installation

3.SIA-TASK front-end project packaging and deployment

4. deployment of task orchestration center (sia-task-config)

5. deployment of task scheduling center (sia-task-scheduler)

After downloading the source code from the clone code repository on github, you canSIA-TASK deployment guideFor details, please refer toSIA-TASK deployment guide

After the SIA-TASK task scheduling platform has been built, the next step is to write task executor instances.

Secondly, according to the development documents, write a TASK actuator instance and start it.

According toSIA-TASK development guideTwo TASK examples, TASKONE (front TASK) and TASKTWO (rear TASK), have been written. seeSIA-TASK development guideThe key configuration of the TASK sample, namely the code, is shown and described in detail below.

This example is a springboot project, and SIA-task-Hunter, the key dependency package of SIA-TASK’s actuator, needs to be introduced through POM files to realize automatic grabbing of Task actuators. First, sia-task-hunter package in SIA-TASK source code needs to be packaged into jar package and installed in local warehouse with mvn install command. sia-task-hunter package in SIA-TASK source code is shown as follows:

Then you can write an example, which mainly includes the following parts:

ConfigurationPOMFile critical dependency

          <!-- 此处添加个性化依赖(sia-task-hunter) -->

Configuration File Main Configuration Items

  # 项目名称(必须)
  spring.application.name: onlinetask-demo
  # 应用端口号(必须)
  server.port: 10086
  # zookeeper地址(必须)
  zooKeeperHosts: *.*.*.*:2181,*.*.*.*:2181,*.*.*.*:2181
  # 是否开启 AOP 切面功能(默认为true)
  spring.aop.auto: true
  # 是否开启 @OnlineTask 串行控制(如果使用则必须开启AOP功能)(默认为true)(可选)
  spring.onlinetask.serial: true

Writing TASK Actuator Main Code

public class OpenTestController {

    @OnlineTask(description = "success,无入参",enableSerial=true)
    @RequestMapping(value = "/success-noparam", method = { RequestMethod.POST }, produces = "application/json;charset=UTF-8")
    @CrossOrigin(methods = { RequestMethod.POST }, origins = "*")
    public String taskOne() {
        Map<String, String> info = new HashMap<String, String>();
        info.put("result", "success-noparam");
        info.put("status", "success");

        return JSONHelper.toString(info);

    @OnlineTask(description = "success,有入参",enableSerial=true)
    @RequestMapping(value = "/success-param", method = { RequestMethod.POST }, produces = "application/json;charset=UTF-8")
    @CrossOrigin(methods = { RequestMethod.POST }, origins = "*")
    public String taskTwo(@RequestBody String json) {
        Map<String, String> info = new HashMap<String, String>();
        info.put("result", "success-param"+"入参是:"+json);
        info.put("status", "success");

        return JSONHelper.toString(info);


After writing the TASK actuator instance, start the process in which the actuator is located.

The startup log is as follows:

The log shows that the process starts normally and TASK actuator information is uploaded to ZK normally.

Observe TASK management interface, as shown in the figure:

As can be seen from the figure, TASK has been synchronized to the database.

Thirdly, JOB creation, job-to-task association and configuration are required.

According tooperating guideDo the following.

Create JOB, configure parameters

Click on the JOB management interfaceAdd Job

Click to enterAdd JobInterface

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

Fill in the Job type and other items separately, and the Job type can also choose FixRate (specific point in time). this example is CRON type, and the specific value is: 0/30 ? A that indicates that it will be executed every 30 seconds from the current time.

clickAdd, adding JOB succeeded.

Configure TASK

After adding a JOB successfully, you need to configure the corresponding TASK for the JOB. You can configure one or more tasks. In this example, you can configure two cascaded tasks.

clickConfigure TASKAfter enteringTask information configurationInterface.

As shown in the above figure, pull both TASK to the right and clickEditButton (pencil shape), enter TASKParameter configurationInterface.

TASKONE parameter configuration:

TASKTWO parameter configuration:

After editing as shown in the figure, clickAdd, TASKONE and TASKTWO were successfully configured into the JOB.

After the addition is completed, you can configure the dependencies of the two TASK, as shown in the following figure:

Use the arrow to point TASKONE to TASK Two to complete the dependency setting between tasks. Click Submit to complete the configuration of the entire JOB. After the configuration is completed, clickTASK informationButton, viewTASK configuration information detailsTo observe the TASK configuration of the JOB.

TASK configuration information map

TASK configuration information details

Finally, activate the JOB and observe the corresponding log.

After TASK is successfully configured, clickState operationIn the drop-down buttonactivationButton to activate the JOB.

After the JOB is activated, refresh the interface, and the scheduler IP and port number can be found in the scheduler of the JOB list (at the red box), indicating that the JOB is preempted by the scheduler after activation.

First observe the management interface JOB and TASK logs

After successfully activating the JOB, enter the scheduling log interface, and after waiting until the JOB execution time, you can view the JOB execution log, as shown in the following figure.

Number 1: represents the JOB log.

Number 2: represents the pre-task (taskone) log associated with the JOB.

Number 3: represents the post TASK(TASKTWO) log associated with the JOB.

Number 4: endTASK is a virtual task added by the system, which only indicates that one scheduling process of the JOB is completed.

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

Observe the actuator TASK instance log again.

You can also observe the TASK log of the actuator instance to verify whether the call was successful.

From the log, it can be seen that the call was indeed successful and it was called every 30 seconds.

Stop JOB

When it is necessary to stop the JOB, clickState operationIn the drop-down buttonStopButton to stop the JOB.

This article is only a preliminary practical use of the microservice TASK scheduling platform SIA-TASK. Through the above description, SIA-TASK can realize the task scheduling function for the actuator instance TASK. The example set up in this article is very simple and suitable for starting SIA-TASK quickly. Of course, SIA-TASK has more powerful task scheduling function and can deal with more complex business scenarios. Everyone can continue to use the experience deeply and combine the function points and business of SIA-TASK to apply it to more complex business scenarios.