Easy Task为简单易用的分布式任务调度平台. An elastic distributed job scheduler system
It is an easy to use distributed task scheduling platform. It is derived from Taobao lottery scheduling platform and has been used in the Taobao content crawling platform and The Tiejia Used Equipment Of Construction Machinery task scheduling platform. It is currently refactored and open source. It has the following characteristics:
If you have several business systems (as worker) that want to use the task scheduling platform, you can download and launch a console directly. The console is also a worker, and can also execute tasks. By default, a demoPlugin task for the demo is started (the actual scene console is only managed, not task execution).
Click “Modify” to view or modify the task configuration. The system is based on spring, and the bean name “demoPlugin” is a built-in spring bean.
Click “Stop” to stop the task.
If you only want to quickly deploy a simple and usable scheduling system, you don’t need to consider the existing business system, you can directly use the task-console source code development.
In actual use, the console is just an administrative task, no tasks are executed, and tasks are executed in the business system. The following simulates scheduling platform is applied to two service systems named “app1” and “app2”. For convenience, still use the task-console.jar for simulation. Before proceeding, first make sure that the above console is still running.
Use the task-spring-boot-client-demo module to explain how to apply the scheduling platform to the spring boot application.
<dependency>
<groupId>com.cehome</groupId>
<artifactId>task</artifactId>
<version>2.0.3</version>
</dependency>
package com.cehome.task.client.demo;
import com.cehome.task.annotation.EnableTimeTaskClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableTimeTaskClient
public class BootApplication {
public static void main(String[] args) {
SpringApplication.run(BootApplication.class,args);
}
}
spring.application.name=boot-client-demo
server.port=8081
#------ main options --------
#应用的名称
task.factory.appName=boot-client-demo
#集群名称(同时也是数据库表名)
task.factory.name=easy_task
#h2数据库配置
task.datasource.driverClassName=org.h2.Driver
task.datasource.url=jdbc:h2:tcp://localhost:9092/~/easy_task_db;MODE=MYSQL
task.datasource.username=sa
task.datasource.password=
#------ client options --------
task.log.packages=ROOT
task.log.path=/logs/easy_task/boot_demo
package com.cehome.task.client.demo;
import com.alibaba.fastjson.JSONObject;
import com.cehome.task.client.TimeTaskContext;
import com.cehome.task.client.TimeTaskPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.net.Inet4Address;
@Component
public class BootDemoPlugin extends TimeTaskPlugin {
private static final Logger logger = LoggerFactory.getLogger(BootDemoPlugin.class);
@Override
public void run(TimeTaskContext context, JSONObject args) throws Exception {
logger.info("plugin class name="+this);
logger.info("task id="+context.getId()+",name="+context.getName());
logger.info("task run on ip="+ Inet4Address.getLocalHost().getHostAddress());
logger.info("task run count="+context.getRunTimes());
}
@Override
public void stop(TimeTaskContext context) throws Exception {
logger.info("task "+context.getName()+" is stopped ");
}
}
The task plugin can also be a normal spring bean, but when configuring the task information in the console, you need to specify the method to be executed.
Use the task-spring-mvc-client-demo module to explain .
<dependency>
<groupId>com.cehome</groupId>
<artifactId>task</artifactId>
<version>2.0.3</version>
</dependency>
<import resource="classpath*:task-client-spring-config.xml"></import>
<context:annotation-config/>
<context:property-placeholder location="classpath*:spring/config.properties"/>
task.factory.appName=mvc-client-demo
task.factory.name=easy_task
#h2
task.datasource.driverClassName=org.h2.Driver
task.datasource.url=jdbc:h2:tcp://localhost:9092/~/easy_task_db;MODE=MYSQL
task.datasource.username=sa
task.datasource.password=
#------ client options --------
task.log.packages=com.cehome.task.client.demo
task.log.path=/logs/easy_task/mvc_demo
<context:component-scan
base-package="com.cehome.task.client.controller"/>
<mvc:annotation-driven />
package com.cehome.task.client.demo;
import com.alibaba.fastjson.JSONObject;
import com.cehome.task.client.TimeTaskContext;
import com.cehome.task.client.TimeTaskPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.net.Inet4Address;
@Component
public class MvcDemoPlugin extends TimeTaskPlugin {
private static final Logger logger = LoggerFactory.getLogger(MvcDemoPlugin.class);
@Override
public void run(TimeTaskContext context, JSONObject args) throws Exception {
logger.info("plugin class name="+this);
logger.info("task id="+context.getId()+"task name="+context.getName());
logger.info("task run on ip="+ Inet4Address.getLocalHost().getHostAddress());
logger.info("task run count="+context.getRunTimes());
}
@Override
public void stop(TimeTaskContext context) throws Exception {
logger.info("task "+context.getName()+" is stopped ");
}
}
The task plugin can also be a normal spring bean, but when configuring the task information in the console, you need to specify the method to be executed.
<context:component-scan base-package="com.cehome.task.client.demo"/>
By default, the console starts an internal database, and the production environment recommends using an external database. Still use the H2 database to illustrate:
task.datasource.driverClassName=org.h2.Driver
task.datasource.url=jdbc:h2:tcp://192.168.0.10:9092/~/easy_task_db;MODE=MYSQL
task.datasource.username=sa
task.datasource.password=
If it is a console, you can modify “task.h2.start=false” to disable the internal database.
task.h2.start=false
task.datasource.driverClassName=com.mysql.jdbc.Driver
task.datasource.url=jdbc:mysql://192.168.0.13:3306/scheduler?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
task.datasource.username=root
task.datasource.password=123456
English(en) and chinese(cn) is supported. Default is english,
Add “language=cn” to application.properties to enable chinese.