[英]Spring batch - executing one step back OR Re-executing previously executed steps
I have a spring batch job with, lets say 5 steps ( step1 --> step2 --> step3 --> step4 --> step5
) . 我有一个春季批处理工作,可以说5个步骤( step1 --> step2 --> step3 --> step4 --> step5
)。 I have configured a StepExectutionListener
, which listens to 2 events 我已经配置了一个StepExectutionListener
,它侦听2个事件
beforeStep()
and afterStep()
for all the steps. 所有步骤的beforeStep()
和afterStep()
。
My question is, if I am in currently beforeStep()
method, and the step to be executed is step2
, can I make spring-batch execute step1
again? 我的问题是,如果我当前处于beforeStep()
方法中,并且要执行的步骤是step2
,我可以再次使spring-batch执行step1
吗? After executing step1
, the flow should continue to step2
, step3
and so on.. 执行后step1
,流动应该继续step2
, step3
等..
To clarify again, can I tell spring-batch to "start execution" from a previously executed step again? 为了再次澄清,我可以告诉spring-batch从先前执行的步骤中再次“开始执行”吗?
While I probably wouldn't recommend this behavior, yes, it should be able to be accomplished. 虽然我可能不推荐这种行为,但是,应该可以实现。 What you'll need to do is to configure step2 to have a transition to step1 with the correct exit code and step1 will need to be able to rerun. 您需要做的是使用正确的退出代码将step2配置为过渡到step1,并且step1必须能够重新运行。
Configuration 组态
<step id="step1" next="step2">
<tasklet ref="someTasklet" allow-start-if-complete="true"/>
</step>
<step id="step2">
<tasklet ref="someOtherTasklet"/>
<listeners>
<listener ref="loopingListener"/>
</listeners>
<next on="BACK" to="step1"/>
</step>
Code 码
public class LoopingListener extends StepExecutionListenerSupport {
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
if(shouldLoop) {
return new ExitStatus("BACK");
} else {
return stepExecution.getExitStatus();
}
}
}
You can achieve a particular ordering of the steps using the following approach. 您可以使用以下方法实现步骤的特定顺序。
<step id="step1" next="step3">
<tasklet>(...)</tasklet>
</step>
next parameter will define which will be executed next. next参数将定义下一个要执行的参数。 However I am not sure whether you can step back in the same execution. 但是我不确定您是否可以退回到同一执行。 But Spring allows you to restart a step if you use the 但是,如果您使用Spring,则可以重新启动步骤
allow-start-if-complete 允许启动,如果完成
to true. 真实。
Also for building workflows, look at http://docs.spring.io/spring-batch/2.2.x/apidocs/org/springframework/batch/core/job/builder/FlowBuilder.SplitBuilder.html 另外,对于构建工作流程,请访问http://docs.spring.io/spring-batch/2.2.x/apidocs/org/springframework/batch/core/job/builder/FlowBuilder.SplitBuilder.html
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.