0
votes

i'm starting a project in spring batch, my plan is like the following:

  1. create spring boot app
  2. expose an api to submit a job(without executing), that will return the job execution id to be able to track the progress of the job later by other clients
  3. create a scheduler for running a job - i want to have a logic that will decide how many jobs i can run at any moment.

the issue is that my batch service may receive many requests for starting jobs, and i want to put the job exeuctuion in a pending status first, then a scheduler later on will check the jobs in pending status and depending on my logic will decide if it should run another set jobs.

is that possible to do in spring batch, or i need to implement it from scratch ?

1

1 Answers

2
votes

The common way of addressing such a use case is to decouple job submission from job execution using a queue. This is described in details in the Launching Batch Jobs through Messages section. Your controller can accept job requests and put them in a queue. The scheduler can then control how many requests to read from the queue and launch jobs accordingly.

Spring Batch provides all building blocks (JobLaunchRequest, JobLaunchingMessageHandler, etc) to implement this pattern.