简体   繁体   English

spring 批量提供作业执行状态和步骤信息

[英]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类用于jobexectionstepexecution 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.

相关问题 失败步骤的Spring批处理作业退出状态 - Spring batch job exit status for failed step 响应主体中的Spring Batch作业执行状态 - Spring Batch job execution status in response body Spring批处理:传播在分区步骤中遇到的异常(停止作业执行) - Spring batch : Propagate exception encountered in partitioned step (Stop job execution) 如何获得Spring Batch作业的下一步中上一步执行的ID? - How do I get the ID of the previous step execution in the next step of a spring batch job? Spring Batch多个作业执行 - Spring Batch Multiple Job execution Spring Batch FlatFileItemReader 在以后的步骤中提供文件名 - Spring Batch FlatFileItemReader provide filename in future step 如何从 Spring Batch Step 访问执行上下文? 错误:没有可用于作业范围的上下文持有者 - How to access execution context from a Spring Batch Step? Error: No context holder available for job scope Spring Batch 3.0:StepExecutionListener 用于分区 Step 并将执行上下文值级联到分区作业 - Spring Batch 3.0 : StepExecutionListener for a partitioned Step and cascading of execution context values to the partitioned job 是否可以使用 Spring Boot Admin 工具监控 Spring Batch 作业执行状态? - Is it possible to monitor Spring Batch job execution status using Spring Boot Admin tool? 如果步骤失败,Spring Batch退出作业 - Spring Batch Exit Job If Step Fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM