IN PROGRESS - BATCH-858: Pause / resume of Job

pausing should now work
This commit is contained in:
robokaso
2008-10-21 16:26:40 +00:00
parent 0d8e32282a
commit 336c267dd8
4 changed files with 34 additions and 13 deletions

View File

@@ -232,16 +232,27 @@ public abstract class AbstractJob implements Job, BeanNameAware, InitializingBea
// The job was already stopped before we even got this far. Deal
// with it in the same way as any other interruption.
execution.setStatus(BatchStatus.STOPPED);
execution.setExitStatus(ExitStatus.FINISHED);
if (execution.getStatus() == BatchStatus.PAUSED) {
// do nothing
}
else {
execution.setStatus(BatchStatus.STOPPED);
execution.setExitStatus(ExitStatus.FINISHED);
}
}
}
catch (JobInterruptedException e) {
logger.error(e);
execution.setExitStatus(ExitStatus.FAILED);
execution.setStatus(BatchStatus.STOPPED);
execution.addFailureException(e);
if (execution.getStatus() == BatchStatus.PAUSED) {
// do nothing
}
else {
execution.setExitStatus(ExitStatus.FAILED);
execution.setStatus(BatchStatus.STOPPED);
execution.addFailureException(e);
}
}
catch (Throwable t) {
logger.error(t);

View File

@@ -87,6 +87,8 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean {
if (lastExecution != null) {
if (lastExecution.getStatus() == BatchStatus.PAUSED) {
jobExecution = lastExecution;
// this execution will be continued => delete the end time
jobExecution.setEndTime(null);
}
else if (!job.isRestartable()) {
throw new JobRestartException("JobInstance already exists and is not restartable");

View File

@@ -320,8 +320,9 @@ public class SimpleJobRepository implements JobRepository {
* @param stepExecution
*/
private void checkForInterruption(StepExecution stepExecution){
jobExecutionDao.synchronizeStatus(stepExecution.getJobExecution());
if(stepExecution.getJobExecution().getStatus() == BatchStatus.STOPPING){
JobExecution jobExecution = stepExecution.getJobExecution();
jobExecutionDao.synchronizeStatus(jobExecution);
if(jobExecution.getStatus() == BatchStatus.STOPPING || jobExecution.getStatus() == BatchStatus.PAUSED){
stepExecution.setTerminateOnly();
}
}

View File

@@ -93,17 +93,24 @@ public class RemoteLauncherTests {
// sleep long enough to avoid race conditions (serializable tx isolation
// doesn't work with HSQL)
Thread.sleep(SLEEP_INTERVAL);
// assertEquals(1, launcher.getRunningExecutions("loopJob").size());
launcher.pause(executionId);
Thread.sleep(SLEEP_INTERVAL);
// assertEquals(0, launcher.getRunningExecutions("loopJob").size());
logger.debug(launcher.getSummary(executionId));
long resumedId = launcher.resume(executionId);
assertEquals("Picked up the same execution after pause and resume", executionId, resumedId);
// launcher.pause(executionId);
// Thread.sleep(SLEEP_INTERVAL);
// long resumeId2 = launcher.resume(executionId);
// assertEquals("Picked up the same execution after pause and resume", executionId, resumeId2);
Thread.sleep(SLEEP_INTERVAL);
launcher.pause(executionId);
Thread.sleep(SLEEP_INTERVAL);
// assertEquals(0, launcher.getRunningExecutions("loopJob").size());
logger.debug(launcher.getSummary(executionId));
long resumeId2 = launcher.resume(executionId);
assertEquals("Picked up the same execution after pause and resume", executionId, resumeId2);
launcher.stop(executionId);
}