How to manually execute Spring batch job?

This is what I need to do for testing purposes. I need a way to execute Spring's batch job whenever I want, based on certain given conditions (e.g. the number of items processed). However, until now I could not find anything like it.

I 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'm looking for looks like this -

 public void myJobFailingMethod() { if(conditionsMatch()) { // fail the job } } 

How to do it?

Update. The task can also be performed outside the step.

+4
source share
1 answer
 public void myJobFailingMethod() { if(conditionsMatch()) { throw new CustomJobFailingException(); // create this exception class. // It will fail the job. } } 
+3
source

Source: https://habr.com/ru/post/1434641/


All Articles