https://github.com/dilermando-lima/spring-schedule-task-runner
Running async tasks in a spring boot api in a managed time and delay execution
https://github.com/dilermando-lima/spring-schedule-task-runner
gradle java java21 scheduled-tasks spring-boot springboot3
Last synced: 23 days ago
JSON representation
Running async tasks in a spring boot api in a managed time and delay execution
- Host: GitHub
- URL: https://github.com/dilermando-lima/spring-schedule-task-runner
- Owner: dilermando-lima
- Created: 2024-07-05T18:02:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-05T18:46:46.000Z (almost 2 years ago)
- Last Synced: 2024-07-06T00:11:15.221Z (almost 2 years ago)
- Topics: gradle, java, java21, scheduled-tasks, spring-boot, springboot3
- Language: Java
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-schedule-task-runner
* [About](#about)
* [Creating a new task implementation](#creating-a-new-task-implementation)
* [Intancing and Starting tasks](#intancing-and-starting-tasks)
* [Set default ThreadPoolTaskSchedule properties](#set-default-threadpooltaskschedule-properties)
## About
This project has a configuration and implementation to running scheduled taks on delay management beetwen each runnning
## Creating a new task implementation
Create a new implementation of managed task, create a class thats implements `ITaskRunner` interface.
```java
public class MyNewTaskRunner implements ITaskRunner {
@Override
public LongSupplier nextExecutionDelayInMilis() {
// it is possible to manage delay of execution getting any data or processing from external services or database.
return () -> TimeUnit.MILLISECONDS.toMillis(1000L); // running every second.
}
@Override
public Runnable runner() {
return () -> {
// doAnythin();
}
}
@Override
public void handleError(Throwable t) {
// handle error on running
LOGGER.error(t.getMessage(), t);
}
}
```
## Intancing and Starting tasks
It's possible to instance many tasks implementations
```java
@Configuration
public class TaskRunnerRegister {
@Bean
public ITaskRunner taskRunner1(){
return new MyNewTaskRunner1();
}
@Bean
public ITaskRunner taskRunner2(){
return new MyNewTaskRunner1();
}
@Bean
public ITaskRunner taskRunner3(){
return new MyNewTaskRunner1();
}
}
```
## Set default ThreadPoolTaskSchedule properties
It's possible to change default settings in `application.properties`
```properties
core.taskrunner.nextExecutionDelayInMilisDefault = 10000;
core.taskrunner.nextExecutionDelayInMilisOnTotalAvailableError = 60000;
core.taskrunner.threadPoolSize = 5;
```