I have an application where clients send HTTP requests which get translated into Spring batch job params and trigger a job. I generate a correlationId
for the response along with the result of the Job Execution.
At this point I have no way to get the Job_Execution_Id
of the job that run.
The way to grab it is If I query BATCH_JOB_EXECUTION_PARAM
table which has the correlationId
as key/value, so I query with condition:
where KEY_NAME='correlationId' AND STRING_VAL='12345'
This gives me the JOB_EXECUTION_ID
.
From here I want to provide my clients with the full detail of the job that run/or is running in progress including the details of the current step and its status. So json payload should look like something like this:
{
"correlationId": "2ae16a63-7e91-4e37-942a-cf7f66117014",
"jobDetails": {
"id": 1,
"jobId": 1,
"jobName": "BLA BLA",
"startTime": "2018-12-23T18:19:13.185",
"endTime": "2018-12-23T18:19:13.223",
"exitCode": "COMPLETED",
"exitDescription": "",
"status": "COMPLETED",
"exceptions": [],
"currentStep": "copyingAFile",
"currentStepStatus": "RUNNING"
},
"_links": {
"self": {
"href": "http://localhost:8080/status/2ae16a63-7e91-4e37-942a-cf7f66117014"
}
}
}
I am aware there are some dao
classes within spring batch for jobexection
and stepexecution
. What I'd like to know is if there a way I can grab the details of the job execution and the current step execution in one hit with a custom query or a dao method that already exists within the spring batch framework and plug into my response? All this from a simple correlationId that my client calls with in an endpoint GET /status/{correlationId}
This link has given me some knowledge but is querying with job execution id which my client will not have and also there is nothing about currentStep
and it's status
I am not driving all this by job execution id because my jobs can be fired asynchronously for which I need to respond immediately with correlationId.
I believe you don't need that correlationId
. If you set an asynchronous task executor on the job launcher, the job launcher will return immediately a jobExecution with an id that you can return to the client, see Running Jobs from within a Web Container .
Now with a job execution Id you get from GET /status/{jobExecutionId}
, you can use a JobExplorer#getJobExecution
to get the JobExecution
and its step executions (using JobExecution#getStepExecutions()
, and find out which step is currently running with stepExecution.getStatus().isRunning()
. With that, you should be able to return your response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.