|
|
@@ -1,6 +1,11 @@
|
|
|
package com.mokamrp.privates.config;
|
|
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.context.event.EventPublishingRunListener;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Conditional;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@@ -8,16 +13,25 @@ import org.springframework.scheduling.TaskScheduler;
|
|
|
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.ErrorHandler;
|
|
|
|
|
|
@Configuration
|
|
|
@Component
|
|
|
public class TaskConfig {
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
|
|
|
@Bean
|
|
|
public TaskScheduler taskScheduler() {
|
|
|
+
|
|
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
|
|
// 设置scheduler执行线程为10个
|
|
|
+
|
|
|
scheduler.setPoolSize(10);
|
|
|
+ if (env.equals("prod")){
|
|
|
+ //.正式环境捕获定时任务异常 推送到飞书
|
|
|
+ scheduler.setErrorHandler(new ScheduledPanic());
|
|
|
+ }
|
|
|
return scheduler;
|
|
|
}
|
|
|
|
|
|
@@ -26,4 +40,6 @@ public class TaskConfig {
|
|
|
public ScheduledAnnotationBeanPostProcessor processor() {
|
|
|
return new ScheduledAnnotationBeanPostProcessor();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|