Spring Party | Graceful termination of work within the framework of work

After starting the task, in the previous task there are certain cases when we want to gracefully finish the job (i.e. do not start the job at all, but do not complain about the .no exception). The current way to do this looks like calling jobExecution.stop. However, this raises a JobInteruptedException, which leads to a logger.error call.

Is there any other more efficient software alternative (without manual intervention)?

+4
source share
3 answers

You can read:

Just enter the end element for your first step based on the condition:

The 'end' element indicates that Job is stopping with BatchStatus COMPLETED.

+2
source
Command

stop () will only be active if the transaction is successful. If all of you are rolling back a rollback, your work does not stop.

I made this workaround: Create a ChunkListener and in the afterChunkError(ChunkContext chunkCtx) put method:

 StepExecution stepExecution = chunkCtx.getStepContext().getStepExecution(); JobExecution jobExecution = jobExplorer.getJobExecution(stepExecution.getJobExecutionId()); if (jobExecution.getStatus().equals(BatchStatus.STOPPING)) { stepExecution.setTerminateOnly(); } 

This will result in a "controlled" stop.

0
source

Instead of calling stop() in the job, try passing it through JobOperator , as shown in Stopping a job

-1
source

Source: https://habr.com/ru/post/1436585/


All Articles