Question

I've been converting a number of nightly scheduled jobs to run one after the next by making a job of jobs. This is totally legit in Spring Batch as a Step can be defined with a reference to another job.

The problem is some of the same child jobs are run on a schedule by Quartz, and they are non-restartable. This means sometimes the "job of jobs" fails because it tries to start an already running job. This yields the much loved:

JobRestartException: JobInstance already exists and is not restartable

My question is whether this is a way to tell Spring Batch to wail until the referenced job is available and then run it. This is because the nightly workflow requires A->B->C. I understand that I can write my own custom job launcher to poll the JobRepository for the offending child job's ExecutionStatus to complete, but I was hoping SB had already thought of this common problem.

Update, example of Job of Jobs for those who asked how it works. The ref's point to jobs that are SimpleJob beans. This works well, but errors as described above when a child job is already running.

<!-- Example Job of Jobs -->
<job id="jobOfJobs">
  <step id="step1">
    <job ref="job1" />
  </step>
  <step id="step2">
    <job ref="job2" />
  </step>
</job>
Was it helpful?

Solution

If you need to manage dependencies between jobs treat them as a step using JobStep

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top