Skip to content

it's a simple way to use the native Spring Framework Scheduling into your spring-boot application keeping the tasks locked during the executions process avoiding multiples executions.

License

nortthon/safe-scheduling

Repository files navigation

Safe Scheduling

License Actions Status Quality Gate Status Maintainability Rating Coverage

What is this?

it's a simple way to use the native Spring Framework Scheduling into your spring-boot application keeping the tasks locked during the executions process avoiding multiples executions.

TaskScheduler Bean

@Configuration
@EnableScheduling
public class SchedulerConfig {
    
    @Bean
    public TaskScheduler taskScheduler(final Provider provider) {
        final LockableTaskScheduler taskScheduler = new LockableTaskScheduler(provider);
        taskScheduler.setPoolSize(1); // Default == 1
        return taskScheduler;
    }
    
    //Provider Bean
}

Use like this

@Component
public class Class {
    @SafeScheduled(name = "scheduler-name", lockedFor = 4000L, cron = "*/5 * * * * *")
    public void execute() {
        //TODO
    }
}

MongoDB Provider

Dependences
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>io.github.nortthon</groupId>
    <artifactId>safe-scheduling-provider-mongodb</artifactId>
    <version>0.2.0</version>
</dependency>
Provider Bean
@Bean
public Provider provider(final MongoTemplate mongoTemplate) {
    new MongoProvider(mongoTemplate);
}

Redis Provider

Dependences
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
    <groupId>io.github.nortthon</groupId>
    <artifactId>safe-scheduling-provider-redis</artifactId>
    <version>0.2.0</version>
</dependency>
Provider Bean
@Bean
public Provider provider(final StringRedisTemplate redisTemplate) {
    new RedisProvider(redisTemplate);
}

About

it's a simple way to use the native Spring Framework Scheduling into your spring-boot application keeping the tasks locked during the executions process avoiding multiples executions.

Resources

License

Stars

Watchers

Forks

Packages 4

 
 
 
 

Languages