[英]What is the best way for softcoding schedule tasks in Spring Boot?
In my Spring program, I have a Scheduled task. 在我的Spring程序中,我有一个计划任务。
@Scheduled(cron = "0 0 0 2 * *") // hardcoded schedule
public void executeBatchJob() {
batchJob.execute();
}
I have a specification change and now have to let the user freely configure the date and time of execution via an API. 我有一个规范更改,现在必须让用户通过API自由配置执行日期和时间。
One way I came up was to run a scheduled task every morning at 0:00 and check if the date is indeed the date of execution. 我出现的一种方法是每天早上0:00运行计划的任务,并检查日期是否确实是执行日期。 If true, check the time of execution and schedule the batch job to run at that time of the day.
如果为true,请检查执行时间并安排批处理作业在一天的该时间运行。
Is there a "Spring" way of achieving this? 有没有实现这一目标的“春季”方式?
Triggers can be used to configure the scheduled jobs. 触发器可用于配置计划的作业。
The basic idea of the Trigger is that execution times may be determined based on past execution outcomes or even arbitrary conditions.
触发器的基本思想是可以根据过去的执行结果甚至任意条件来确定执行时间。
Check out this answer for detailed explanation. 查看此答案以获取详细说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.