Reputation: 15389
This is something I need to do for testing purposes. I need a way to fail a Spring Batch job whenever I want based on certain preset conditions (such as number of items processed). However, I haven't been able to find anything like this so far.
I have found that Spring Batch has something like this -
<step id="step1" parent="s1" next="step2">
<step id="step2" parent="s2">
<fail on="FAILED" exit-code="EARLY TERMINATION"/>
<next on="*" to="step3"/>
</step>
<step id="step3" parent="s3">
But what I am looking for is something like this-
public void myJobFailingMethod()
{
if(conditionsMatch())
{
// fail the job
}
}
How to do this?
Update: The Job can be failed outside a step as well.
Upvotes: 5
Views: 11044
Reputation: 15389
public void myJobFailingMethod()
{
if(conditionsMatch())
{
throw new CustomJobFailingException(); // create this exception class.
// It will fail the job.
}
}
Upvotes: 4