Dependency tree from spring batch configuration
Having a spring job definition:
<job id="footballJob"开发者_如何转开发>
<!-- Step bean details ommitted for clarity -->
<step id="playerload" next="gameLoad"/>
<step id="gameLoad" next="playerSummarization"/>
<step id="playerSummarization"/>
</job>
Can I progmatically figure out the order of steps to execute?
Can I progmatically figure out the order of steps to execute?
by taking your question literally there are some options:
- use Spring Tool Suite afaik it can display job flows
- parse job.xml by yourself, you could even use a spring batch job which would be quite funny
- try to grok the complete batch setup process, start with spring.handlers and CoreNamespaceHandler.java, you can overwrite it by your needs
- SimpleFlow.java should be sufficient
i would go with a simple xml parser
Steps will execute in order that you listed in your example.
In case you'd like to specify the order you can do:
<job id="job">
<step id="stepA" parent="s1" next="stepB" />
<step id="stepB" parent="s2" next="stepC"/>
<step id="stepC" parent="s3" />
</job>
In case you'd like a non sequential step execution / conditional flow, you can do:
<job id="job">
<step id="stepA" parent="s1">
<next on="*" to="stepB" />
<next on="FAILED" to="stepC" />
</step>
<step id="stepB" parent="s2" next="stepC" />
<step id="stepC" parent="s3" />
</job>
In order to control the flow programmatically, depending on ExitStatus
, you can inject your own decider
:
public class MyDecider implements JobExecutionDecider {
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
if (someCondition) {
return "FAILED";
}
else {
return "COMPLETED";
}
}
}
In the job configuration, a "decision" tag will specify the decider to use as well as all of the transitions:
<job id="job">
<step id="step1" parent="s1" next="decision" />
<decision id="decision" decider="decider">
<next on="FAILED" to="step2" />
<next on="COMPLETED" to="step3" />
</decision>
<step id="step2" parent="s2" next="step3"/>
<step id="step3" parent="s3" />
</job>
<beans:bean id="decider" class="com.MyDecider"/>
EDIT:
If you are looking to get a dependency graph
, you can just use Spring Tool Suite to visualize the flow, here is a simple example.
精彩评论