vendredi 20 février 2015

Transition from nested job to "main job"

I have 2 job xmls


1.Main_job.xml



<batch:job id="main_job">
<batch:step id="dummyTask1">
<batch:tasklet ref="dummyTask" />
<batch:next on="FORWARD" to="dummyTask2"/>
</batch:step>
<batch:step id="dummyTask2">
<batch:job ref="nested_job" /> <!--Forking a nested job -->
<batch:next on="BACKWARD" to="dummyTask1"/>
<batch:next on="FORWARD" to="dummyTask3"/>
</batch:step>
<batch:step id="dummyTask3">
<batch:tasklet ref="dummyTask" />
<batch:next on="BACKWARD" to="dummyTask2"/>
<batch:next on="FORWARD" to="endTask"/>
</batch:step>
<batch:step id="endTask">
<batch:tasklet ref="endTask" />
</batch:step>
</batch:job>


2.nested_job.xml



<batch:job id="nested_job">
<batch:step id="dummyTask10">
<batch:tasklet ref="dummyTask" />
<batch:next on="FORWARD" to="dummyTask11"/>
</batch:step>
<batch:step id="dummyTask11">
<batch:tasklet ref="dummyTask" />
<batch:next on="BACKWARD" to="dummyTask10"/>
<batch:next on="FORWARD" to="dummyTask12"/>
</batch:step>
<batch:step id="dummyTask12">
<batch:tasklet ref="dummyTask" />
<batch:next on="BACKWARD" to="dummyTask11"/>
<batch:next on="FORWARD" to="endTask"/>
</batch:step>
<batch:step id="endTask">
<batch:tasklet ref="endTask" />
</batch:step>
</batch:job>


You can see that, all the steps have 2 paths.



  1. FORWARD

  2. BACKWARD


And these paths gets chosen depending on some dynamic boolean condition. Let us say, first, all the Exit codes for the step gets evaluated to FORWARD. So these are the sequence of steps, which gets executed



1. dummyTask1
2. dummyTask2
[Nested_job] 3.dummyTask10
[Nested_job] 4.dummyTask11
[Nested_job] 5.dummyTask12


Let us say when the execution point is on dummyTask12, the Exit codes starts to get evaluated to BACKWARD. So following are the step executions for the same



[Nested_job] 5.dummyTask12
[Nested_job] 4.dummyTask11
[Nested_job] 5.dummyTask10


Now for dummyTask10, when the exit code comes as BACKWARD, SpringBatch throws error saying that flow doesn't exist, which is true (dummyTask10 doesn't have the flow defined for code BACKWARDS). What I want to achieve is, incase of BACKWARD, the flow should go back to main_job (or any Main job which has triggered this nested job (dynamically) )


Is this possible? Is it possible to have a flow definition like this, which will take the execution point to the main job, which forked this nested job?



<batch:next on="BACKWARD" to="#{mainJob}"/> <!-- Or something -->


[I know this is a little more to ask for, But I am sure SpringBatch experts will find a way to achieve this]


Please let me know if you need more clarity.


EDIT:


From a nested job (nested_job), can I write a flow like below within a step, which will make transition to main job?



<batch:next on="BACKWARD" to="main_job.dummyTask1"/>

Aucun commentaire:

Enregistrer un commentaire