Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide method for stopping Batch 5 Jobs upon user request #5990

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ public int stopAll() {
Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions();
for (JobExecution jobExecution : result) {
try {
jobExecution.getStepExecutions().forEach(StepExecution::setTerminateOnly);
jobExecution.setStatus( BatchStatus.STOPPING);
jobRepository.update(jobExecution);
stop(jobExecution.getId());
onobc marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception e) {
throw new IllegalArgumentException("The following JobExecutionId was not found: " + jobExecution.getId(), e);
}
Expand All @@ -246,7 +244,7 @@ public JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException
// 'STOPPING'. It is assumed that
// the step implementation will check this status at chunk boundaries.
logger.info("Stopping job execution: " + jobExecution);

jobExecution.getStepExecutions().forEach(StepExecution::setTerminateOnly);
jobExecution.setStatus(BatchStatus.STOPPING);
onobc marked this conversation as resolved.
Show resolved Hide resolved
jobRepository.update(jobExecution);
return jobExecution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import javax.sql.DataSource;

import org.junit.jupiter.api.Test;
import org.springframework.batch.core.launch.JobExecutionNotRunningException;
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
import org.testcontainers.containers.JdbcDatabaseContainer;

import org.springframework.batch.core.BatchStatus;
Expand Down Expand Up @@ -192,6 +194,18 @@ void exceptionsShouldBeThrownIfRequestForNonExistingJobInstance() {
@Test
void stoppingJobExecutionShouldLeaveJobExecutionWithStatusOfStopping() throws Exception {
JobExecution jobExecution = createJobExecution(BASE_JOB_INST_NAME,true);
assertJobHasStopped(jobExecution);
}

@Test
void stoppingAllJobExecutionsShouldLeaveJobExecutionsWithStatusOfStopping() throws Exception {
JobExecution jobExecutionOne = createJobExecution(BASE_JOB_INST_NAME,true);
JobExecution jobExecutionTwo = createJobExecution(BASE_JOB_INST_NAME+"_TWO",true);
assertJobHasStopped(jobExecutionOne);
assertJobHasStopped(jobExecutionTwo);
}

private void assertJobHasStopped(JobExecution jobExecution) throws NoSuchJobExecutionException, JobExecutionNotRunningException {
jobExecution = jobService.getJobExecution(jobExecution.getId());
assertThat(jobExecution.isRunning()).isTrue();
onobc marked this conversation as resolved.
Show resolved Hide resolved
assertThat(jobExecution.getStatus()).isNotEqualTo(BatchStatus.STOPPING);
Expand Down
Loading