RESOLVED BATCH-1030: Added BatchStatus.INCOMPLETE.

This commit is contained in:
dsyer
2009-02-01 09:56:22 +00:00
parent a6767ebdf5
commit f47e8382d2
4 changed files with 34 additions and 7 deletions

View File

@@ -32,9 +32,11 @@ public enum BatchStatus {
* execution are COMPLETED will the aggregate status be COMPLETED. A running
* execution is expected to move from STARTING to STARTED to COMPLETED
* (through the order defined by {@link #upgradeTo(BatchStatus)}). Higher
* values than STARTED signify more serious failure.
* values than STARTED signify more serious failure. INCOMPLETE is used for
* steps that have finished processing, but were not successful, and where
* they should be skipped on a restart (so FAILED is the wrong status).
*/
COMPLETED, STARTING, STARTED, FAILED, STOPPING, STOPPED, UNKNOWN;
INCOMPLETE, COMPLETED, STARTING, STARTED, FAILED, STOPPING, STOPPED, UNKNOWN;
public static BatchStatus max(BatchStatus status1, BatchStatus status2) {
if (status1.isLessThan(status2)) {
@@ -57,12 +59,13 @@ public enum BatchStatus {
}
/**
* Convenience method to decide if a status indicates execution was unsuccessful.
* Convenience method to decide if a status indicates execution was
* unsuccessful.
*
* @return true if the status is FAILED or greater
*/
public boolean isUnsuccessful() {
return this==FAILED || this.isGreaterThan(FAILED);
return this == FAILED || this.isGreaterThan(FAILED);
}
/**
@@ -104,4 +107,12 @@ public enum BatchStatus {
return this.compareTo(other) < 0;
}
/**
* @param other a status value to compare
* @return true if this is less than other
*/
public boolean isLessThanOrEqualTo(BatchStatus other) {
return this.compareTo(other) <= 0;
}
}

View File

@@ -339,6 +339,17 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea
}
/**
* Convenience method for subclasses so they can change the state of a
* {@link StepExecution} if necessary. Use with care (and not at all
* preferably) and only before or after a step is executed.
*
* @param stepExecution
*/
protected void updateStepExecution(StepExecution stepExecution) {
jobRepository.update(stepExecution);
}
/**
* Given a step and configuration, return true if the step should start,
* false if it should not, and throw an exception if the job should finish.
@@ -368,7 +379,7 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea
+ "so it may be dangerous to proceed. " + "Manual intervention is probably necessary.");
}
if (stepStatus == BatchStatus.COMPLETED && step.isAllowStartIfComplete() == false) {
if (stepStatus.isLessThanOrEqualTo(BatchStatus.COMPLETED) && step.isAllowStartIfComplete() == false) {
// step is complete, false should be returned, indicating that the
// step should not be started
return false;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.batch.core.job.flow;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.JobInterruptedException;
@@ -142,6 +143,11 @@ public class FlowJob extends AbstractJob {
}
public String executeStep(Step step) throws JobInterruptedException, JobRestartException, StartLimitExceededException {
StepExecution lastStepExecution = stepExecutionHolder.get();
if (lastStepExecution!=null && lastStepExecution.getStatus()==BatchStatus.FAILED) {
lastStepExecution.setStatus(BatchStatus.INCOMPLETE);
updateStepExecution(lastStepExecution);
}
StepExecution stepExecution = handleStep(step, execution);
stepExecutionHolder.set(stepExecution);
return stepExecution==null ? FlowExecution.COMPLETED : stepExecution.getExitStatus().getExitCode();

View File

@@ -143,8 +143,7 @@ public class FlowJobTests {
fail = false;
job.execute(jobExecution);
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
// TODO: fix this (BATCH-1030)
// assertEquals(1, jobExecution.getStepExecutions().size());
assertEquals(1, jobExecution.getStepExecutions().size());
}
@Test