[英]spring batch provide status of job execution and step information
I have an application where clients send HTTP requests which get translated into Spring batch job params and trigger a job.我有一个应用程序,客户端发送 HTTP 请求,这些请求被翻译成 Spring 批处理作业参数并触发作业。 I generate a
correlationId
for the response along with the result of the Job Execution.我为响应生成一个
correlationId
以及作业执行的结果。
At this point I have no way to get the Job_Execution_Id
of the job that run.此时我无法获取运行的作业的
Job_Execution_Id
。
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:获取它的方法是如果我查询
BATCH_JOB_EXECUTION_PARAM
表,其中correlationId
作为键/值,所以我查询条件:
where KEY_NAME='correlationId' AND STRING_VAL='12345'
This gives me the JOB_EXECUTION_ID
.这给了我
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:
所以 json 有效载荷应该是这样的:
{
"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
.我知道 spring 批处理中有一些
dao
类用于jobexection
和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?我想知道的是,是否有一种方法可以通过自定义查询或 spring 批处理框架中已存在的 dao 方法一次性获取作业执行和当前步骤执行的详细信息并插入我的响应中? All this from a simple correlationId that my client calls with in an endpoint
GET /status/{correlationId}
所有这些都来自我的客户端在端点
GET /status/{correlationId}
中调用的一个简单的 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这个链接给了我一些知识,但正在查询我的客户不会有的作业执行 ID,也没有关于
currentStep
和它的状态
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.我不是通过作业执行 ID 来驱动所有这些,因为我的作业可以异步触发,为此我需要立即使用 correlationId 进行响应。
I believe you don't need that correlationId
.我相信您不需要那个
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 .如果您在作业启动器上设置异步任务执行器,作业启动器将立即返回一个 jobExecution,您可以将其返回给客户端,请参阅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.现在有了从
GET /status/{jobExecutionId}
获得的作业执行 ID,您可以使用JobExplorer#getJobExecution
获取JobExecution
及其步骤执行(使用JobExecution#getStepExecutions()
,并找出当前正在运行的步骤stepExecution.getStatus().isRunning()
有了它,您应该能够返回您的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.