Skip to content

Commit

Permalink
[Bug] [Server] Once click online schedule time, task will be automati…
Browse files Browse the repository at this point in the history
…cally scheduled (#13092)

* fix bug that trigger mis-fire strategy when setting start time earlier than current time

* update ut

* add warning msg

* add check start time when set schedule online

(cherry picked from commit 7497b26)
  • Loading branch information
Radeity authored and zhongjiajie committed Dec 28, 2022
1 parent e028e64 commit bc95715
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public enum Status {
COMMAND_STATE_COUNT_ERROR(80001, "task instance state count error", "查询各状态任务实例数错误"),
NEGTIVE_SIZE_NUMBER_ERROR(80002, "query size number error", "查询size错误"),
START_TIME_BIGGER_THAN_END_TIME_ERROR(80003, "start time bigger than end time error", "开始时间在结束时间之后错误"),
START_TIME_BEFORE_CURRENT_TIME_ERROR(80004, "start time before current time error", "开始时间在当前时间之前错误"),
QUEUE_COUNT_ERROR(90001, "queue count error", "查询队列数据错误"),

KERBEROS_STARTUP_STATE(100001, "get kerberos startup state error", "获取kerberos启动状态错误"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,18 @@ public Map<String, Object> insertSchedule(User loginUser,
scheduleObj.setProcessDefinitionName(processDefinition.getName());

ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class);
if (now.after(scheduleParam.getStartTime())) {
logger.warn("The start time must be later than current time.");
putMsg(result, Status.START_TIME_BEFORE_CURRENT_TIME_ERROR);
return result;
}
if (DateUtils.differSec(scheduleParam.getStartTime(), scheduleParam.getEndTime()) == 0) {
logger.warn("The start time must not be the same as the end");
putMsg(result, Status.SCHEDULE_START_TIME_END_TIME_SAME);
return result;
}
if (scheduleParam.getStartTime().getTime() > scheduleParam.getEndTime().getTime()) {
logger.warn("The start time must smaller than end time");
logger.warn("The start time must be smaller than end time.");
putMsg(result, Status.START_TIME_BIGGER_THAN_END_TIME_ERROR);
return result;
}
Expand Down Expand Up @@ -319,6 +324,13 @@ public Map<String, Object> setScheduleState(User loginUser,
return result;
}
if (scheduleStatus == ReleaseState.ONLINE) {
// check schedule start time
Date now = new Date();
if (now.after(scheduleObj.getStartTime())) {
logger.warn("The start time must be later than current time.");
putMsg(result, Status.START_TIME_BEFORE_CURRENT_TIME_ERROR);
return result;
}
// check process definition release state
if (processDefinition.getReleaseState() != ReleaseState.ONLINE) {
logger.info("not release process definition id: {} , name : {}",
Expand Down Expand Up @@ -667,13 +679,18 @@ private void updateSchedule(Map<String, Object> result,
putMsg(result, Status.PARSE_TO_CRON_EXPRESSION_ERROR);
return;
}
if (now.after(scheduleParam.getStartTime())) {
logger.warn("The start time must be later than current time.");
putMsg(result, Status.START_TIME_BEFORE_CURRENT_TIME_ERROR);
return;
}
if (DateUtils.differSec(scheduleParam.getStartTime(), scheduleParam.getEndTime()) == 0) {
logger.warn("The start time must not be the same as the end");
putMsg(result, Status.SCHEDULE_START_TIME_END_TIME_SAME);
return;
}
if (scheduleParam.getStartTime().getTime() > scheduleParam.getEndTime().getTime()) {
logger.warn("The start time must smaller than end time");
logger.warn("The start time must be smaller than end time.");
putMsg(result, Status.START_TIME_BIGGER_THAN_END_TIME_ERROR);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public class SchedulerServiceTest {
@InjectMocks
private QuartzExecutorImpl quartzExecutors;

protected static User user;
protected Exception exception;
private static final String userName = "userName";
private static final String projectName = "projectName";
private static final long projectCode = 1L;
private static final int userId = 1;
private static final String processDefinitionName = "processDefinitionName";
private static final long processDefinitionCode = 2L;
private static final int processDefinitionVersion = 3;
private static final int scheduleId = 3;
private static final long environmentCode = 4L;
private static final String startTime = "2220-01-01 12:13:14";
private static final String endTime = "2220-02-01 12:13:14";
private static final String crontab = "0 0 * * * ? *";

@Before
public void setUp() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useForm = () => {
timingFormRef: ref(),
timingForm: {
startEndTime: [
new Date(year, month, day),
new Date(year, month, day + 1),
new Date(year + 100, month, day)
],
crontab: '0 0 * * * ? *',
Expand Down

0 comments on commit bc95715

Please sign in to comment.