Skip to content

Commit

Permalink
#30367 Improvements on the cancel process
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Dec 4, 2024
1 parent d5facb6 commit fdb6134
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void cancelJob(final String jobId) throws DotDataException {

final Job job = getJob(jobId);

if (job.state() == JobState.PENDING || job.state() == JobState.RUNNING) {
if (isInCancelableState(job)) {
handleJobCancelRequest(job);
} else {
Logger.warn(this, "Job " + job.id() + " is not in a cancellable state. "
Expand All @@ -427,9 +427,7 @@ void onCancelRequestJob(final JobCancelRequestEvent event) {
try {

final var job = getJob(event.getJob().id());
if (job.state() == JobState.PENDING
|| job.state() == JobState.RUNNING
|| job.state() == JobState.CANCEL_REQUESTED) {
if (isInCancelableState(job) || job.state() == JobState.CANCEL_REQUESTED) {

final Optional<JobProcessor> instance = getInstance(job.id());
if (instance.isPresent()) {
Expand Down Expand Up @@ -1136,6 +1134,18 @@ private int incrementAndResetEmptyQueueCount(
return emptyQueueCount;
}

/**
* Verifies if a job state is in a cancellable state.
*
* @param job The job to check.
* @return {@code true} if the job is in a cancellable state, {@code false} otherwise.
*/
private boolean isInCancelableState(final Job job) {
return job.state() == JobState.PENDING || job.state() == JobState.RUNNING
|| job.state() == JobState.FAILED || job.state() == JobState.ABANDONED
|| job.state() == JobState.ABANDONED_PERMANENTLY;
}

/**
* A wrapper class that makes ScheduledExecutorService auto-closeable. This class is designed to
* be used with try-with-resources to ensure that the ScheduledExecutorService is properly shut
Expand Down

0 comments on commit fdb6134

Please sign in to comment.