Skip to content

Commit

Permalink
add isValidExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchaoxu committed Dec 28, 2023
1 parent 82094a1 commit 67d653f
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil;
import com.nb6868.onex.job.JobConst;
import com.nb6868.onex.job.entity.JobEntity;
import com.nb6868.onex.job.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronExpression;
import org.springframework.scheduling.support.CronTrigger;

/**
Expand All @@ -18,7 +20,7 @@
public abstract class BaseJobConfig implements SchedulingConfigurer {

@Autowired
private JobService jobService;
JobService jobService;

/**
* 添加trigger
Expand All @@ -38,7 +40,8 @@ protected void initTrigger(ScheduledTaskRegistrar taskRegistrar, Long jobId) {
log.info("TriggerTask next Trigger");
// 配置参数要再从数据库读一遍,否则不会变更
JobEntity job = jobService.getById(jobId);
if (ObjectUtil.isNotNull(job) && StrUtil.isNotBlank(job.getCron())) {
// 加入cron的校验
if (ObjectUtil.isNotNull(job) && StrUtil.isNotBlank(job.getCron()) && CronExpression.isValidExpression(job.getCron())) {
return new CronTrigger(job.getCron()).nextExecution(triggerContext);
} else {
return null;
Expand Down

0 comments on commit 67d653f

Please sign in to comment.