-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scheduler configuration added to update statistics
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...lorer-web/src/main/java/org/royllo/explorer/web/configuration/SchedulerConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.royllo.explorer.web.configuration; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.royllo.explorer.core.util.base.BaseConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.scheduling.TaskScheduler; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||
|
||
/** | ||
* Scheduler configuration. | ||
*/ | ||
@Profile("!scheduler-disabled") | ||
@Configuration | ||
@EnableScheduling | ||
@RequiredArgsConstructor | ||
public class SchedulerConfiguration extends BaseConfiguration { | ||
|
||
/** Termination delay in milliseconds (10 000 ms = 10 seconds). */ | ||
private static final int TERMINATION_DELAY_IN_MILLISECONDS = 10_000; | ||
|
||
/** | ||
* Configure the task scheduler. | ||
* | ||
* @return task scheduler | ||
*/ | ||
@Bean | ||
public TaskScheduler taskScheduler() { | ||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); | ||
scheduler.setWaitForTasksToCompleteOnShutdown(true); | ||
scheduler.setAwaitTerminationMillis(TERMINATION_DELAY_IN_MILLISECONDS); | ||
scheduler.setThreadNamePrefix("royllo-process-"); | ||
scheduler.setErrorHandler(throwable -> { | ||
try { | ||
logger.error("Error while processing requests: {}", throwable.getMessage()); | ||
} catch (Exception exception) { | ||
logger.error("Error while processing requests: {}", exception.getMessage()); | ||
} | ||
}); | ||
return scheduler; | ||
} | ||
|
||
} |