Closed
Description
I cannot implement this functional interface with ShedLock. It throws an error complaining about trying to inject a proxy.
@Override
public void configureTasks(ScheduledTaskRegistrar registrar) {
registrar.setTaskScheduler(taskScheduler());
}
My setup:
@Bean(name = "taskExecutor")
@Primary
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setThreadNamePrefix("async-");
executor.setAllowCoreThreadTimeOut(true);
executor.setWaitForTasksToCompleteOnShutdown(true);
return executor;
}
@Bean(name = "taskScheduler")
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(50);
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setErrorHandler(t -> log.error(
"Unknown error occurred while executing task.", t
));
scheduler.setRejectedExecutionHandler(
(r, e) -> log.error(
"Execution of task {} was rejected for unknown reasons.", r
)
);
return scheduler;
}
@Bean(name = "scheduledLockConfiguration")
public ScheduledLockConfiguration scheduledLockConfiguration(TaskScheduler taskScheduler, LockProvider lockProvider) {
return ScheduledLockConfigurationBuilder
.withLockProvider(lockProvider)
.withTaskScheduler(taskScheduler)
.withDefaultLockAtMostFor(Duration.ofMinutes(10))
.build();
}
@Bean(name = "lockProvider")
public LockProvider lockProvider(MongoClient mongo) {
return new MongoLockProvider(mongo, "my_db");
}
Activity
lukas-krecan commentedon Dec 18, 2018
Hi, can you please try newest version 2.2.0 with annotation based config (as described in readme)? It should work better than ScheduledLockConfiguration. Please, let me know if it helps.
bjornharvold commentedon Dec 19, 2018
Hi @lukas-krecan
I actually had that annotation on there already but I also had the ScheduledLockConfiguration bean definition.
This still fails:
lukas-krecan commentedon Dec 19, 2018
You are right, it's indeed a bug. I will take a look at it in next few days. Thanks for reporting.
lukas-krecan commentedon Dec 19, 2018
Actually, there is an easy workaround, return type of
taskScheduler
method should beTaskScheduler
and notThreadPoolTaskScheduler
.bjornharvold commentedon Dec 19, 2018
Hi @lukas-krecan
That was indeed an oversight on my side. Not even a workaround ;-) That's the proper way to do it!
Thank you.
sanderdewinter commentedon May 8, 2019
Hi, I'm sorry to interrupt to use this closed issue.
I think I found some related issue on Stackoverflow which we do run into as well.
It might be due to the usage of the
messageBrokerTaskScheduler
bean defined inAbstractMessageBrokerConfiguration
, or check the docs.Could you please shed some light on this?
lukas-krecan commentedon May 8, 2019
I have answered the SO question https://stackoverflow.com/questions/56017382/how-to-fix-websockets-and-shedlock-compatibility-in-spring-boot-application/56036601#56036601
sanderdewinter commentedon May 8, 2019
@lukas-krecan Thanks for you help! 👍