Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat](job)Internal job cancellation immediately and the strong association with the STARTS parameter #36805

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void analyze(Analyzer analyzer) throws UserException {
if (null != onceJobStartTimestamp) {
if (onceJobStartTimestamp.equalsIgnoreCase(CURRENT_TIMESTAMP_STRING)) {
jobExecutionConfiguration.setImmediate(true);
timerDefinition.setStartTimeMs(System.currentTimeMillis());
} else {
timerDefinition.setStartTimeMs(TimeUtils.timeStringToLong(onceJobStartTimestamp));
}
Expand All @@ -149,6 +150,8 @@ public void analyze(Analyzer analyzer) throws UserException {
if (null != startsTimeStamp) {
if (startsTimeStamp.equalsIgnoreCase(CURRENT_TIMESTAMP_STRING)) {
jobExecutionConfiguration.setImmediate(true);
//To avoid immediate re-scheduling, set the start time of the timer 100ms before the current time.
timerDefinition.setStartTimeMs(System.currentTimeMillis());
} else {
timerDefinition.setStartTimeMs(TimeUtils.timeStringToLong(startsTimeStamp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public void checkParams() {
if (executeType == JobExecuteType.INSTANT || executeType == JobExecuteType.MANUAL) {
return;
}

checkTimerDefinition(immediate);

checkTimerDefinition();
if (executeType == JobExecuteType.ONE_TIME) {
validateStartTimeMs();
return;
Expand All @@ -80,12 +78,12 @@ public void checkParams() {
}
}

private void checkTimerDefinition(boolean immediate) {
private void checkTimerDefinition() {
if (timerDefinition == null) {
throw new IllegalArgumentException(
"timerDefinition cannot be null when executeType is not instant or manual");
}
timerDefinition.checkParams(immediate);
timerDefinition.checkParams();
}

private void validateStartTimeMs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ public class TimerDefinition {
private Long latestSchedulerTimeMs;


public void checkParams(boolean immediate) {
if (null != startTimeMs && immediate) {
throw new IllegalArgumentException("startTimeMs must be null when immediate is true");
}
if (null == startTimeMs && immediate) {
startTimeMs = System.currentTimeMillis();
}
public void checkParams() {
if (null == startTimeMs) {
startTimeMs = System.currentTimeMillis() + intervalUnit.getIntervalMs(interval);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public void scheduleOneJob(T job) throws JobException {
schedulerInstantJob(job, TaskType.SCHEDULED, null);
}
}
if (job.getJobConfig().isImmediate() && JobExecuteType.ONE_TIME.equals(job.getJobConfig().getExecuteType())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why JobExecuteType == ONE_TIME ,can not setLatestSchedulerTimeMs(System.currentTimeMillis())?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is not persistent, so for a one-time, immediately scheduled task, there's no need to set it.

schedulerInstantJob(job, TaskType.SCHEDULED, null);
return;
}
//RECURRING job and immediate is true
if (job.getJobConfig().isImmediate()) {
job.getJobConfig().getTimerDefinition().setLatestSchedulerTimeMs(System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void testImmediate() {
JobExecutionConfiguration configuration = new JobExecutionConfiguration();
configuration.setExecuteType(JobExecuteType.ONE_TIME);
configuration.setImmediate(true);
configuration.setImmediate(true);
TimerDefinition timerDefinition = new TimerDefinition();
timerDefinition.setStartTimeMs(0L);
configuration.setTimerDefinition(timerDefinition);
configuration.checkParams();
}
Expand Down
Loading