Skip to content

ScorpioAeolus/dcs-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dcs-scheduler

Apache License 2 Build Status

DCS scheduler is a decentralized distributed task scheduling tool developed based on the principles of Spring scheduler and Shedlock. Currently, it supports using MySQL, Redis, and Zookeeper as coordinators, and supports Spring scheduler annotation as tasks, which eliminates programmatic tasks. It uses Shedlock's locking principle to support only one task node executing at a time, which eliminates Shedlock's SpEL expression capability (as a task, it generally does not require dynamic parameters).

Implementation principle

During spring startup, when calling the postProcessAfterInitialization method of DcsScheduledAnnotationBeanPostProcessor to encapsulate the method with DcsScheduled annotation into a task, the Shedlock locking logic is embedded, which saves the AOP facet processing method of Shedlock.

Supported Provider Types

  • mysql
  • redis
  • zookeeper

How to use?

1.Import Dependency
<dependency>
  <groupId>io.github.scorpioaeolus</groupId>
  <artifactId>dcs-scheduler</artifactId>
  <version>{version}</version>
</dependency>
2.Enable scheduler capability
@SpringBootApplication
@EnableDcsScheduling(providerModel=DB,defaultLockAtMostFor = "10m")
public class XxxApplication {
    public static void main(String[] args) {
        SpringApplication.run(XxxApplication.class, args);
    }
}
3.Add task annotations
@DcsScheduled(fixedRate = 5000l,name = "executeHandler")
public void executeHandler3() {
    log.info("executeHandler3 exec,thread-id={}",Thread.currentThread().getId());
}
4.Provider preparation

for db,you should add table structure:

CREATE TABLE shedlock(name VARCHAR(64) NOT NULL, lock_until TIMESTAMP(3) NOT NULL,
    locked_at TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), locked_by VARCHAR(255) NOT NULL, PRIMARY KEY (name));

and you should also expose the bean of the Data Source.

for redis,you should expose the bean of the RedisConnectionFactory.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

for zookeeper,you should expose the bean of the CuratorFramework:

<dependency>
  <groupId>org.apache.curator</groupId>
  <artifactId>curator-framework</artifactId>
</dependency>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages