feat: 外部化定时任务配置至application.yml
将WeatherDataScheduleTask和OutageStateSetScheduledTask中的硬编码cron表达式移至配置文件,提升配置灵活性,便于不同环境调整执行时间。
This commit is contained in:
parent
e07412904f
commit
8cfb78b8af
@ -20,7 +20,7 @@ public class OutageStateSetScheduledTask {
|
|||||||
@Resource
|
@Resource
|
||||||
private IDnerHourlyPowerOutageEventService hourlyPowerOutageEventService;
|
private IDnerHourlyPowerOutageEventService hourlyPowerOutageEventService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 0 * * ?")
|
@Scheduled(cron = "${schedule.outage-state-set}")
|
||||||
public void schedule() {
|
public void schedule() {
|
||||||
log.info("【设置已复电状态任务】定时触发--开始");
|
log.info("【设置已复电状态任务】定时触发--开始");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class WeatherDataScheduleTask {
|
|||||||
/**
|
/**
|
||||||
* 每小时第20分钟执行
|
* 每小时第20分钟执行
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 20 * * * ?")
|
@Scheduled(cron = "${schedule.weather-data-sync}")
|
||||||
public void schedule() {
|
public void schedule() {
|
||||||
log.info("【区域天气数据同步任务】定时触发--开始");
|
log.info("【区域天气数据同步任务】定时触发--开始");
|
||||||
execute();
|
execute();
|
||||||
|
|||||||
@ -53,4 +53,7 @@ async:
|
|||||||
keep-alive-seconds: 60 # 空闲线程存活时间(秒),实现线程回收
|
keep-alive-seconds: 60 # 空闲线程存活时间(秒),实现线程回收
|
||||||
await-termination-seconds: 60 # 优雅停机:等待任务完成的最大时长(秒)
|
await-termination-seconds: 60 # 优雅停机:等待任务完成的最大时长(秒)
|
||||||
|
|
||||||
|
# 定时任务配置
|
||||||
|
schedule:
|
||||||
|
weather-data-sync: "0 20 * * * ?" # 区域天气数据同步任务:每小时第20分钟执行
|
||||||
|
outage-state-set: "0 0 0 * * ?" # 设置已复电状态任务:每天凌晨执行
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user