Elia Rohana
Elia Rohana

Reputation: 326

spring batch -how to submit jobs without executing ? to be able to run them later by a scheduler

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 ?

Upvotes: 0

Views: 987

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31600

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.

Upvotes: 2

Related Questions