fix: 开关定时任务,后台定时扫描执行。
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.intc.iot.task;
|
||||
|
||||
import com.intc.iot.service.TimingCtrlExecuteService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 开关定时任务执行扫描
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(TimingCtrlExecuteService.class)
|
||||
public class TimingCtrlExecuteTask {
|
||||
|
||||
private static final long SCAN_DELAY_MS = 300000L;
|
||||
|
||||
private final TimingCtrlExecuteService timingCtrlExecuteService;
|
||||
|
||||
/**
|
||||
* 每5分钟扫描一次启用中的每天循环定时控制
|
||||
*/
|
||||
@Scheduled(fixedDelay = SCAN_DELAY_MS)
|
||||
public void scanDailyTimingCtrl() {
|
||||
try {
|
||||
int count = timingCtrlExecuteService.scanAndExecuteDailyTimingCtrl();
|
||||
if (count > 0) {
|
||||
log.info("[TimingCtrlTask] 本次扫描执行了 {} 条定时控制", count);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[TimingCtrlTask] 扫描定时控制失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user