IN PROGRESS - BATCH-505: Job-level ExecutionContext
JobExecutionContext is now persisted (together with StepExecutionContext) and retrieved on restart (changed jobExecution's start time to be not null so that last execution can be always found).
This commit is contained in:
@@ -38,13 +38,13 @@ public class JobExecution extends Entity {
|
||||
|
||||
private volatile BatchStatus status = BatchStatus.STARTING;
|
||||
|
||||
private volatile Date startTime = null;
|
||||
private volatile Date startTime = new Date(System.currentTimeMillis());
|
||||
|
||||
private volatile Date endTime = null;
|
||||
|
||||
private volatile ExitStatus exitStatus = ExitStatus.UNKNOWN;
|
||||
|
||||
private ExecutionContext executionContext;
|
||||
private ExecutionContext executionContext = new ExecutionContext();
|
||||
|
||||
/**
|
||||
* Because a JobExecution isn't valid unless the job is set, this
|
||||
|
||||
@@ -54,6 +54,13 @@ public class SimpleJob extends AbstractJob {
|
||||
|
||||
JobInstance jobInstance = execution.getJobInstance();
|
||||
|
||||
boolean isJobRestart = getJobRepository().getJobExecutionCount(jobInstance) > 0;
|
||||
if (isJobRestart) {
|
||||
execution.setExecutionContext(getJobRepository().getLastJobExecution(jobInstance).getExecutionContext());
|
||||
} else {
|
||||
execution.setExecutionContext(new ExecutionContext());
|
||||
}
|
||||
|
||||
StepExecution currentStepExecution = null;
|
||||
int startedCount = 0;
|
||||
List steps = getSteps();
|
||||
|
||||
@@ -111,5 +111,16 @@ public interface JobRepository {
|
||||
* @return the execution count of the step within the given job instance.
|
||||
*/
|
||||
int getStepExecutionCount(JobInstance jobInstance, Step step);
|
||||
|
||||
/**
|
||||
* @return the execution count of the given job instance.
|
||||
*/
|
||||
int getJobExecutionCount(JobInstance jobInstance);
|
||||
|
||||
/**
|
||||
* @return the last execution of the given job instance.
|
||||
*/
|
||||
JobExecution getLastJobExecution(JobInstance jobInstance);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -247,6 +247,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
public void saveOrUpdateExecutionContext(StepExecution stepExecution) {
|
||||
saveOrUpdate(stepExecution);
|
||||
stepExecutionDao.saveOrUpdateExecutionContext(stepExecution);
|
||||
jobExecutionDao.saveOrUpdateExecutionContext(stepExecution.getJobExecution());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,5 +290,28 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of executions of the given job instance
|
||||
*/
|
||||
public int getJobExecutionCount(JobInstance jobInstance) {
|
||||
|
||||
return jobExecutionDao.findJobExecutions(jobInstance).size();
|
||||
}
|
||||
|
||||
public JobExecution getLastJobExecution(JobInstance jobInstance) {
|
||||
List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance);
|
||||
if (jobExecutions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
JobExecution lastExecution = (JobExecution) jobExecutions.get(0);
|
||||
for (Iterator iterator = jobExecutions.iterator(); iterator.hasNext();) {
|
||||
JobExecution exec = (JobExecution) iterator.next();
|
||||
if (lastExecution.getStartTime().getTime() < exec.getStartTime().getTime()) {
|
||||
lastExecution = exec;
|
||||
}
|
||||
}
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user