Change job dispatcher sort order to: restart jobs, non-wf jobs, creation date

Description

Currently, the order in which the jobs are dispatched doesn't match the comments in the code. This is very confusing for someone looking at the code and trying to debug a problem and also the comments make more sense than what the method is actually doing.
So the new order will be: restarting jobs are dispatched first, then non-workflow jobs and, if both match, jobs that were created before are dispatched first.
The dispatcher comparison will be something like:

private static final class DispatchableComparator implements Comparator<Job> {

@Override
public int compare(Job jobA, Job jobB) {

// Jobs that are in "restart" mode should be handled first
if (Job.Status.RESTART.equals(jobA.getStatus()) && !Job.Status.RESTART.equals(jobB.getStatus())) {
return -1;
} else if (Job.Status.RESTART.equals(jobB.getStatus()) && !Job.Status.RESTART.equals(jobA.getStatus())) {
return 1;
}

// Regular jobs should be processed prior to workflow and workflow operation jobs
if (TYPE_WORKFLOW.equals(jobA.getJobType()) && !TYPE_WORKFLOW.equals(jobB.getJobType())) {
return 1;
} else if (TYPE_WORKFLOW.equals(jobB.getJobType()) && !TYPE_WORKFLOW.equals(jobA.getJobType())) {
return -1;
}

// Use date_created
if (jobA.getDateCreated() != null && jobB.getDateCreated() != null) {
if (jobA.getDateCreated().getTime() < jobB.getDateCreated().getTime())
return -1;
else if (jobA.getDateCreated().getTime() > jobB.getDateCreated().getTime())
return 1;
}

// Undecided
return 0;
}

}

Assignee

Rute Santos

Reporter

Rute Santos

Tags (folksonomy)

None

Components

Fix versions

Affects versions

Priority

Major
Configure