I have a task with 3 different batch jobs. If one of them fails and I restart that particular one the new task execution gives the Command Line runner error as it runs the task with the same parameters as the previous task. What is the workaround for this?
Asked
Active
Viewed 125 times
0
-
Can you elaborate with an example to reproduce the issue? See https://stackoverflow.com/help/mcve – Mahmoud Ben Hassine Sep 24 '18 at 13:19
-
Hey, so this can only be descriptive. Basically, I have a task with multiple batch jobs. Let's say 3. Now if 2 pass and 1 fails, I would want to restart the failed batch job. When I try to do this I would want only the failed job to run again but in the current case it just starts the task again and runs all the jobs with the same params again. – Siddhant Sorann Sep 25 '18 at 05:49
-
Have you tried to set `restartable=false` on the jobs? – Mahmoud Ben Hassine Sep 25 '18 at 10:25
-
Yeah, issue isn't with it not restarting. Issue is that i only want the failed job to restart and not the ones which completed. – Siddhant Sorann Sep 25 '18 at 11:05
-
Is there something preventing you from having a task per job? This would solve your problem by design. You would only restart the task of the failed job. – Mahmoud Ben Hassine Sep 25 '18 at 11:26
-
Currently I have about 50+ jobs defined via xml files in one project. So creating a single jar for each will be a big task. – Siddhant Sorann Sep 26 '18 at 08:27
-
You can keep your single jar but create a task definition per job using the property `spring.batch.job.names=job1`, `spring.batch.job.names=job2`, etc. So you would have a single task app but with 50+ task definitions, one per job. – Mahmoud Ben Hassine Sep 26 '18 at 09:33
-
Yeah, that's what i'm planning on doing now. Thanks. Also, would you have any idea if there is another property to order the jobs as well? And also how to use the spring.cloud.task.batch.failOnJobFailure=true property. I get a null exception when i add it to my task and run it. – Siddhant Sorann Sep 26 '18 at 10:43
-
To order the jobs, use the same property. For example `spring.batch.job.names=job2,job1` will run job2 then job1. See here: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java#L141. For the other question in regards to `spring.cloud.task.batch.failOnJobFailure=true `, please open another question on SO. – Mahmoud Ben Hassine Sep 26 '18 at 11:49
-
Hey, so i tried giving job2, job1 but it still runs job1 before it runs job2. And i created https://stackoverflow.com/questions/52531263/spring-cloud-task-status-shown-as-complete-even-when-the-batch-job-fails for the other issue. Thanks! – Siddhant Sorann Sep 27 '18 at 07:02