0
votes

Suppose I want to build an API for (1) submitting jobs to be executed and (2) later get their result/status.

Now, the submit endpoint receives a payload and some headers. The payload is persisted through a custom JpaRepository and the headers are pushed into an instance of JobParameters (which is then fed to the JobLauncher). From what I know so far, there is a JobRepository that will end up persisting my JobParameters.

A. My first question on this design would be: should the JobRepository be used to persist the job payload instead of doing it in a custom JpaRepository?

B. I want access the JobParameters of a certain job (by job ID, which is given back when a job is submitted to the JobLauncher, through the JobExecution; this is standard Spring Batch stuff).

Is this possible from a normal bean (a @Service class)?

  • The JobRepository does not expose anything that access a job id and returns the job parameters associated with that.

  • There is a JobExecutionDao that, given an execution ID, could give me access to the JobParameters, but I cannot inject that into my beans.

Parameter <#> of constructor in required a bean of type 'org.springframework.batch.core.repository.dao.JobExecutionDao' that could not be found.

1
This does not qualify as an answer, but from codecentric's (no affiliation) batch-web-spring-boot-starter github.com/codecentric/spring-boot-starter-batch-web/blob/… you should be able to glean the relevant API (and then post the answer yourself).Stefan Reisner
What does the request payload contain?Mahmoud Ben Hassine

1 Answers

1
votes

I will answer your questions and then give you an idea about how I would do it.

A. My first question on this design would be: should the JobRepository be used to persist the job payload instead of doing it in a custom JpaRepository?

It depends on the request payload. The job repository should be enough to store job meta-data.

B. I want access the JobParameters of a certain job (by job ID, which is given back when a job is submitted to the JobLauncher, through the JobExecution; this is standard Spring Batch stuff).

Given a job execution id, you can get the parameters using JobOperator#getParameters(Long executionId)

Now the following is how I would implement your requirement:

Suppose I want to build an API for (1) submitting jobs to be executed and (2) later get their result/status.