feat: 外部化定时任务配置至application.yml

将WeatherDataScheduleTask和OutageStateSetScheduledTask中的硬编码cron表达式移至配置文件,提升配置灵活性,便于不同环境调整执行时间。
This commit is contained in:
yufengshuo 2026-03-31 10:55:46 +08:00
parent e07412904f
commit 8cfb78b8af
3 changed files with 6 additions and 3 deletions

View File

@ -20,7 +20,7 @@ public class OutageStateSetScheduledTask {
@Resource
private IDnerHourlyPowerOutageEventService hourlyPowerOutageEventService;
@Scheduled(cron = "0 0 0 * * ?")
@Scheduled(cron = "${schedule.outage-state-set}")
public void schedule() {
log.info("【设置已复电状态任务】定时触发--开始");
try {

View File

@ -23,7 +23,7 @@ public class WeatherDataScheduleTask {
/**
* 每小时第20分钟执行
*/
@Scheduled(cron = "0 20 * * * ?")
@Scheduled(cron = "${schedule.weather-data-sync}")
public void schedule() {
log.info("【区域天气数据同步任务】定时触发--开始");
execute();

View File

@ -53,4 +53,7 @@ async:
keep-alive-seconds: 60 # 空闲线程存活时间(秒),实现线程回收
await-termination-seconds: 60 # 优雅停机:等待任务完成的最大时长(秒)
# 定时任务配置
schedule:
weather-data-sync: "0 20 * * * ?" # 区域天气数据同步任务每小时第20分钟执行
outage-state-set: "0 0 0 * * ?" # 设置已复电状态任务:每天凌晨执行