如何解决设置动态cron
我们有这样一种方法:
public boolean isHoliday(int year,int month,int day) {
Query query = em.createNativeQuery(" select * from holiday where year= " + year+ " and month= " + = + " and daily= "+ daily);
return !query.getResultList().isEmpty();
}
因此我们将假期保存在sql表中。
但是我需要根据15后的第一个工作日进行批处理。一个月中的某天。每月一次。
这是小任务:
@Component
public class DocumentReconciliationMonthlyJobTasklet extends Tasklet{
private final Logger logger = LoggerFactory.getLogger(DocumentReconciliationMonthlyJobTasklet.class);
@Autowired
private Environment env;
@Autowired
@Qualifier("restTemplateMediumTimeout")
private RestTemplate restTemplate;
@Override
public RepeatStatus doExecute(StepContribution contribution,ChunkContext chunkContext) throws Exception {
logger.info("DocumentReconciliationMonthlyJobTasklet started");
restTemplate.getForEntity(url+ serviceUrl,String.class);
这是配置:
@Bean
public FactoryBean documentReconciliationScheduledMonthlyJob() {
FactoryBean bean = new JobFactoryBean();
bean.setBatchJobName(JOB_NAME);
bean.setCronExp(CRON_EXPRESSION_FOR_JOB);
bean.setNonXAcrmDataSource(this.nonXAcrmDataSource);
return bean;
}
我如何从sql中获取并设置为cron?它应该每月运行一次。
每天进行批处理工作,并检查该方法是否可以运行?
或者我如何通过从该sql获取动态设置下一个运行时间?例如,每月的10个批次将正常工作并将下一次运行时间设置为15?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。