Skip to content

Commit 1da2f28

Browse files
committed
Fix step execution context is not persisted and restored
1. Step execution context is not persisted in `SimpleStepExecutionSplitter::split` 2. Step execution context is not restored in `SimpleJobRepository::getStepExecution` Closes GH-5138 Signed-off-by: Yanming Zhou <[email protected]>
1 parent 088487b commit 1da2f28

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*
4646
* @author Dave Syer
4747
* @author Mahmoud Ben Hassine
48+
* @author Yanming Zhou
4849
* @since 2.0
4950
*/
5051
public class SimpleStepExecutionSplitter implements StepExecutionSplitter {
@@ -138,13 +139,15 @@ public Set<StepExecution> split(StepExecution stepExecution, int gridSize) throw
138139
if (lastStepExecution == null) { // fresh start
139140
StepExecution currentStepExecution = jobRepository.createStepExecution(stepName, jobExecution);
140141
currentStepExecution.setExecutionContext(context.getValue());
142+
jobRepository.updateExecutionContext(currentStepExecution);
141143
set.add(currentStepExecution);
142144
}
143145
else { // restart
144146
if (lastStepExecution.getStatus() != BatchStatus.COMPLETED
145147
&& shouldStart(allowStartIfComplete, stepExecution, lastStepExecution)) {
146148
StepExecution currentStepExecution = jobRepository.createStepExecution(stepName, jobExecution);
147149
currentStepExecution.setExecutionContext(lastStepExecution.getExecutionContext());
150+
jobRepository.updateExecutionContext(currentStepExecution);
148151
set.add(currentStepExecution);
149152
}
150153
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/explore/support/SimpleJobExplorer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Mahmoud Ben Hassine
4545
* @author Parikshit Dutta
4646
* @author Glenn Renfro
47+
* @author Yanming Zhou
4748
* @see JobExplorer
4849
* @see JobInstanceDao
4950
* @see JobExecutionDao
@@ -287,7 +288,7 @@ public long getStepExecutionCount(JobInstance jobInstance, String stepName) thro
287288
return stepExecutionDao.countStepExecutions(jobInstance, stepName);
288289
}
289290

290-
private void getStepExecutionDependencies(StepExecution stepExecution) {
291+
protected void getStepExecutionDependencies(StepExecution stepExecution) {
291292
if (stepExecution != null) {
292293
stepExecution.setExecutionContext(ecDao.getExecutionContext(stepExecution));
293294
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* @author Baris Cubukcuoglu
5353
* @author Parikshit Dutta
5454
* @author Mark John Moreno
55+
* @author Yanming Zhou
5556
* @see JobRepository
5657
* @see JobInstanceDao
5758
* @see JobExecutionDao
@@ -82,7 +83,9 @@ public List<JobInstance> findJobInstances(String jobName) {
8283
@Nullable
8384
@Override
8485
public StepExecution getStepExecution(long executionId) {
85-
return this.stepExecutionDao.getStepExecution(executionId);
86+
StepExecution stepExecution = this.stepExecutionDao.getStepExecution(executionId);
87+
getStepExecutionDependencies(stepExecution);
88+
return stepExecution;
8689
}
8790

8891
/**

0 commit comments

Comments
 (0)