Spring Batch job execution status in response body

Josh

I'm very new to Spring Batch and pretty confused

I've got a controller with some request mappings. When I get a certain URL I want to print the job status to the response body. Here's some code:

@RequestMapping(value = "/batchExecution", method = RequestMethod.GET)
@ResponseBody
public String getJobExecutionStatus() {
    return "Hello world!";
}

I've tried adding JobExecution to the method, but can you only access these elements with the JobExecutionListener?

@RequestMapping(value = "/batchExecution", method = RequestMethod.GET)
@ResponseBody
public String getJobExecutionStatus(JobExecution jobExecution) {
    return "Hello world!";
}

sorry for my noobie questions, I can't find any documentation on what I'm looking for

Josh

To resolve this issue I was able to answer my own question with the help of Pospolita Nikita's comments on my original post.

I implemented a service with a process method, and then called that method in my program controller. The code looks like this:

Service

@Override
    public String process(Long jobId) throws Exception {
        BatchStatus jobStatus = explorer.getJobExecution(jobId).getStatus();
        LOGGER.info("The Job ID is: " + jobId);
        LOGGER.info("The job status is: "+jobStatus);
        return null;
    }

Controller

@RequestMapping(value = "/batchMonitor/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<String> process(@PathVariable("id") Long id) {
        HttpHeaders responseHeaders = MccControllerUtils.createCacheDisabledHeaders();
        responseHeaders.setContentType(MediaType.TEXT_HTML);
        try {
            LOGGER.info("Obtaining job by ID " + id);
            String response = batchService.process(id);
            return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            LOGGER.error("Error obtaining batch by ID " + id, e);
            return new ResponseEntity<>(e.getMessage(), responseHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

Hopefully this can help someone else down the road. Thanks!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to access execution context from a Spring Batch Step? Error: No context holder available for job scope

分類Dev

How to update jsp status (from submitted to processing then success )if a spring batch job runing in background that will update a sql result status

分類Dev

Disable transactions in my Spring Batch job

分類Dev

Testing of spring batch job causes unexpected results

分類Dev

Spring Batch Persist Job Meta Data

分類Dev

NoSuchJobException when running a job programmatically in Spring Batch

分類Dev

pass job parameters to custom writer Spring batch

分類Dev

Can I use Spring JdbcTemplate in Spring Batch Job Implementation?

分類Dev

How to modify slim v3 response body before and after route execution?

分類Dev

Check status of AWS job

分類Dev

無限ループで実行されているSpring Batch Job

分類Dev

プログラムでSpring Batch Jobを実行しますか?

分類Dev

Does every job call in Spring Batch open a new database connection pool?

分類Dev

Deadlock while purging old records of spring batch job tables at scheduled time using shedlock

分類Dev

Streaming okhttp response body

分類Dev

Spring Batchは常にSpring Bootで始まります:spring.batch.job.enabled = false動作しません

分類Dev

Access status response

分類Dev

Separate execution status of piped commands

分類Dev

For Loop Ends Batch File Execution

分類Dev

Spring XD: pipe (>) from file source to batch job fails (IllegalArgumentException: Unable to convert provided JSON to Map<String, Object>)

分類Dev

golang unzip Response.Body

分類Dev

Response body when PATCHing a collection

分類Dev

Remote Job execution with non terminating Return

分類Dev

Return response with status code in Express

分類Dev

How to change the order of function body execution?

分類Dev

Batch Timeout /nobreak constant response

分類Dev

SSIS Package Stuck at "Created Execution" Status

分類Dev

Getting input data after execution of batch file

分類Dev

Appropriate response for job result in REST API

Related 関連記事

  1. 1

    How to access execution context from a Spring Batch Step? Error: No context holder available for job scope

  2. 2

    How to update jsp status (from submitted to processing then success )if a spring batch job runing in background that will update a sql result status

  3. 3

    Disable transactions in my Spring Batch job

  4. 4

    Testing of spring batch job causes unexpected results

  5. 5

    Spring Batch Persist Job Meta Data

  6. 6

    NoSuchJobException when running a job programmatically in Spring Batch

  7. 7

    pass job parameters to custom writer Spring batch

  8. 8

    Can I use Spring JdbcTemplate in Spring Batch Job Implementation?

  9. 9

    How to modify slim v3 response body before and after route execution?

  10. 10

    Check status of AWS job

  11. 11

    無限ループで実行されているSpring Batch Job

  12. 12

    プログラムでSpring Batch Jobを実行しますか?

  13. 13

    Does every job call in Spring Batch open a new database connection pool?

  14. 14

    Deadlock while purging old records of spring batch job tables at scheduled time using shedlock

  15. 15

    Streaming okhttp response body

  16. 16

    Spring Batchは常にSpring Bootで始まります:spring.batch.job.enabled = false動作しません

  17. 17

    Access status response

  18. 18

    Separate execution status of piped commands

  19. 19

    For Loop Ends Batch File Execution

  20. 20

    Spring XD: pipe (>) from file source to batch job fails (IllegalArgumentException: Unable to convert provided JSON to Map<String, Object>)

  21. 21

    golang unzip Response.Body

  22. 22

    Response body when PATCHing a collection

  23. 23

    Remote Job execution with non terminating Return

  24. 24

    Return response with status code in Express

  25. 25

    How to change the order of function body execution?

  26. 26

    Batch Timeout /nobreak constant response

  27. 27

    SSIS Package Stuck at "Created Execution" Status

  28. 28

    Getting input data after execution of batch file

  29. 29

    Appropriate response for job result in REST API

ホットタグ

アーカイブ