Make the meaning of running status consistent

- A running status is STARTING, STARTED, or STOPPING.
- Update related tests.

 Resolves #1483
This commit is contained in:
Marvin Deng
2022-05-11 23:50:19 +08:00
committed by Mahmoud Ben Hassine
parent 930bb0243c
commit bbf35b79f7
12 changed files with 79 additions and 12 deletions

View File

@@ -84,10 +84,10 @@ public enum BatchStatus {
/**
* Convenience method to decide if a status indicates that work is in progress.
* @return true if the status is STARTING, STARTED
* @return true if the status is STARTING, STARTED, STOPPING
*/
public boolean isRunning() {
return this == STARTING || this == STARTED;
return this == STARTING || this == STARTED || this == STOPPING;
}
/**

View File

@@ -256,10 +256,11 @@ public class JobExecution extends Entity {
/**
* Test if this {@link JobExecution} indicates that it is running. Note that this does
* not necessarily mean that it has been persisted.
* @return {@code true} if the end time is null and the start time is not null.
* @return {@code true} if the status is one of the running statuses.
* @see BatchStatus#isRunning()
*/
public boolean isRunning() {
return startTime != null && endTime == null;
return status.isRunning();
}
/**

View File

@@ -119,7 +119,7 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean {
*/
for (StepExecution execution : lastExecution.getStepExecutions()) {
BatchStatus status = execution.getStatus();
if (status.isRunning() || status == BatchStatus.STOPPING) {
if (status.isRunning()) {
throw new JobExecutionAlreadyRunningException(
"A job execution for this job is already running: " + lastExecution);
}

View File

@@ -88,7 +88,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
+ " from %PREFIX%JOB_EXECUTION where JOB_EXECUTION_ID = ?";
private static final String GET_RUNNING_EXECUTIONS = "SELECT E.JOB_EXECUTION_ID, E.START_TIME, E.END_TIME, E.STATUS, E.EXIT_CODE, E.EXIT_MESSAGE, E.CREATE_TIME, E.LAST_UPDATED, E.VERSION, "
+ "E.JOB_INSTANCE_ID from %PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I where E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID and I.JOB_NAME=? and E.START_TIME is not NULL and E.END_TIME is NULL order by E.JOB_EXECUTION_ID desc";
+ "E.JOB_INSTANCE_ID from %PREFIX%JOB_EXECUTION E, %PREFIX%JOB_INSTANCE I where E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID and I.JOB_NAME=? and E.STATUS in ('STARTING', 'STARTED', 'STOPPING') order by E.JOB_EXECUTION_ID desc";
private static final String CURRENT_VERSION_JOB_EXECUTION = "SELECT VERSION FROM %PREFIX%JOB_EXECUTION WHERE JOB_EXECUTION_ID=?";

View File

@@ -136,7 +136,7 @@ public class SimpleJobRepository implements JobRepository {
// check for running executions and find the last started
for (JobExecution execution : executions) {
if (execution.isRunning() || execution.isStopping()) {
if (execution.isRunning()) {
throw new JobExecutionAlreadyRunningException(
"A job execution for this job is already running: " + jobInstance);
}