Skip to content

Commit

Permalink
Scheduler configuration added to update statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Jan 4, 2024
1 parent 268c462 commit 9df98da
Showing 1 changed file with 45 additions and 0 deletions.
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;
}

}

0 comments on commit 9df98da

Please sign in to comment.