Giter VIP home page Giter VIP logo

hsweb-task's Introduction

任务模块

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

hsweb-task's People

Contributors

zhou-hao avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.