org.hswebframework:hsweb-task-spring-boot-starter

轻量级任务调度框架

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

org.hswebframework
ArtifactId

ArtifactId

hsweb-task-spring-boot-starter
Last Version

Last Version

1.0.0-RC
Release Date

Release Date

Type

Type

jar
Description

Description

轻量级任务调度框架

Download hsweb-task-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/org.hswebframework/hsweb-task-spring-boot-starter/ -->
<dependency>
    <groupId>org.hswebframework</groupId>
    <artifactId>hsweb-task-spring-boot-starter</artifactId>
    <version>1.0.0-RC</version>
</dependency>
// https://jarcasting.com/artifacts/org.hswebframework/hsweb-task-spring-boot-starter/
implementation 'org.hswebframework:hsweb-task-spring-boot-starter:1.0.0-RC'
// https://jarcasting.com/artifacts/org.hswebframework/hsweb-task-spring-boot-starter/
implementation ("org.hswebframework:hsweb-task-spring-boot-starter:1.0.0-RC")
'org.hswebframework:hsweb-task-spring-boot-starter:jar:1.0.0-RC'
<dependency org="org.hswebframework" name="hsweb-task-spring-boot-starter" rev="1.0.0-RC">
  <artifact name="hsweb-task-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.hswebframework', module='hsweb-task-spring-boot-starter', version='1.0.0-RC')
)
libraryDependencies += "org.hswebframework" % "hsweb-task-spring-boot-starter" % "1.0.0-RC"
[org.hswebframework/hsweb-task-spring-boot-starter "1.0.0-RC"]

Dependencies

compile (8)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 1.5.13.RELEASE
org.hswebframework : hsweb-task-core jar 1.0.0-RC
org.springframework.boot : spring-boot-starter jar 1.5.13.RELEASE
org.springframework : spring-context jar 4.3.17.RELEASE
org.hswebframework : hsweb-task-cluster Optional jar 1.0.0-RC
org.redisson : redisson Optional jar 3.8.1
org.projectlombok : lombok jar 1.16.18
org.slf4j : slf4j-api jar 1.7.25

test (7)

Group / Artifact Type Version
org.spockframework : spock-spring jar 1.0-groovy-2.4
org.spockframework : spock-core jar 1.0-groovy-2.4
com.athaydes : spock-reports jar 1.2.13
org.codehaus.groovy : groovy-all jar 2.4.15
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
ch.qos.logback : logback-classic jar 1.1.7

Project Modules

There are no modules declared in this project.

任务模块

Maven Central Build Status codecov License

提供任务配置,调度,监控. 支持单节点,集群,分布式部署.支持多种任务配置方式: 注解, jar包, 脚本(js,groovy)

单点模式

引入依赖

<dependency>
    <groupId>org.hswebframework</groupId>
    <artifactId>hsweb-task-spring-boot-starter</artifactId>
    <version>${hsweb.task.version}</version>
</dependency>
 @SpringBootApplication
 @EnableTaskWorker
 @EnableTaskScheduler
 public class Application{
    
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
         
    //使用注解方式定义一个任务,并指定调度规则
    @Job(id="test.job",name="测试任务")
    @Scheduled(cron="0 0/1 * * * ?") //支持spring的Scheduled注解
    public void myJob(){
        System.out.println("执行任务");
    }
 }

分布式模式

在worker和scheduler都引入依赖

<dependency>
    <groupId>org.hswebframework</groupId>
    <artifactId>hsweb-task-spring-boot-starter</artifactId>
    <version>${hsweb.task.version}</version>
</dependency>
<dependency>
    <groupId>org.hswebframework</groupId>
    <artifactId>hsweb-task-cluster</artifactId>
    <version>${hsweb.task.version}</version>
</dependency>
<!--使用redisson作为redis客户端进行集群管理-->
<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson</artifactId>
    <version>3.8.2</version>
</dependency>

application.yml

hsweb: 
    task:
      cluster: #集群管理配置,默认使用redis进行集群管理
        redis:
          hosts: redis://127.0.0.1:8761
          database: 1
      worker:
       # id: ${spring.application.name}-${HOSTNAME} #默认使用此ID,不同的节点id必须不同.
        name: worker-node-1
        groups: ${spring.application.name} #worker将执行这些分组的任务
        client-group: ${spring.application.name} #worker作为client自动提交任务时,将使用此分组,必须为groups属性的子集

定义worker

@SpringBootApplication
@EnableTaskWorker
public class Application{
   
   public static void main(String[] args) {
       SpringApplication.run(Application.class);
   }
        
   //使用注解方式定义一个任务,并指定调度规则
   @Job(id="test.job",name="测试任务")
   @Scheduled(cron="0 0/1 * * * ?") //支持spring的Scheduled注解
   public void myJob(){
       System.out.println("执行任务");
   }
}

定义scheduler

 @SpringBootApplication
 @EnableTaskScheduler
 public class Application{
     public static void main(String[] args) {
         SpringApplication.run(Application.class);
     }
 }

application.yml

hsweb: 
    task:
      cluster:
        redis:
          address: redis://127.0.0.1:8761
          database: 1
      scheduler:
#        id: ${spring.application.name}-${HOSTNAME} #默认使用此ID
org.hswebframework

企业后台管理系统基础框架

hsweb(haʊs wɛb)后台管理基础框架,快速开发企业后台管理应用。

Versions

Version
1.0.0-RC