jaredb
jaredb

Reputation: 21

Asynchronous Spring Batch Job multiple steps flow control

I have a spring batch job configured to run asynchronously (being started from a web service and using annotations to configure the methods to be asynchronous) my first step runs successfully.

My issue is that I have multiple steps configured and the flow is determined on the status of the step i.e. on completed it moves to step 2 but on a failure it moves to a failure handling step which sends a mail. When a remove the annotations the flow appears to work as expected. However when I use the annotations to run the job asynchronously which ever step is configured to execute on completion gets executed. flow configuration sample:

<batch:job id="batchJob" restartable="true">
    <batch:step id="step1">
        <batch:tasklet ref="task1">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:next on="HAS_ERRORS" to="reportError" />
        <batch:end on="*" />
        <batch:next on="COMPLETED" to="step2" />
    </batch:step>
    <batch:step id="step2">
        <batch:tasklet ref="task2">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:next on="HAS_ERRORS" to="reportError" />
        <batch:end on="*" />            
    </batch:step>
    <batch:step id="reportError">
        <batch:tasklet ref="failError">
            <batch:listeners>
                <batch:listener ref="failureHandler" />
            </batch:listeners>
        </batch:tasklet>
        <batch:end on="*" />
    </batch:step>
</batch:job>

I have attempted to return an ExitStatus and a BatchStatus which has been ignored.

I have implemented a step execution listener but I have not yet implemented a messaging mechanism to communicate across steps and I do not see anything in the step execution context which gives me an indication of the outcome of the step.

The question I have is whether or not there is a method or mechanism that I may have overlooked to get the status of a step once it's completed? or is a messaging mechanism outside of the batch process an accepted way of proceeding?

It feels wrong that I cannot see the status of the batch step once it's completed when it's asynchronous(I get the expected results/failures when I remove the @Async annotation) I think there might be something I'm missing in my understanding I've spent some time looking into it so a pointer in the right direction would be appreciated.

Upvotes: 1

Views: 2078

Answers (1)

jaredb
jaredb

Reputation: 21

I do not have access to this particular code any more.

I believe the issue is caused by the annotations overriding the XML configuration which defined the expected flow.

By overriding this we change the actual flow which we expected.

Upvotes: 1

Related Questions