StartTime is now honored for TaskExecution

regardless if they were created before or during task execution.

resolves #861

Readded check for duplicate launch request
This commit is contained in:
Glenn Renfro
2022-09-14 11:00:12 -04:00
parent 0bfacb193b
commit bda4cd1917
2 changed files with 29 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -276,14 +276,13 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
Assert.notNull(taskExecution,
String.format("Invalid TaskExecution, ID %s not found",
this.taskProperties.getExecutionid()));
Assert.isNull(taskExecution.getEndTime(), String.format(
"Invalid TaskExecution, ID %s task is already complete",
Assert.isNull(taskExecution.getEndTime(),
String.format("Invalid TaskExecution, ID %s task is already complete",
this.taskProperties.getExecutionid()));
this.taskExecution = this.taskRepository.startTaskExecution(
this.taskProperties.getExecutionid(),
this.taskNameResolver.getTaskName(), new Date(), args,
this.taskProperties.getExternalExecutionId(),
this.taskProperties.getParentExecutionId());
Date startDate = (taskExecution.getStartTime() == null) ? new Date() : taskExecution.getStartTime();
this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(),
this.taskNameResolver.getTaskName(), startDate, args,
this.taskProperties.getExternalExecutionId(), this.taskProperties.getParentExecutionId());
}
else {
TaskExecution taskExecution = new TaskExecution();

View File

@@ -20,6 +20,7 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -197,6 +198,27 @@ public class TaskStartTests {
.isEqualTo("batchEvents");
}
@Test
public void testWithGeneratedTaskExecutionWithExistingDate() throws Exception {
final String TASK_EXECUTION_NAME = "PRE-EXECUTION-TEST-NAME";
Date startDate = new Date();
Thread.sleep(500);
TaskExecution taskExecution = new TaskExecution(1, 0, TASK_EXECUTION_NAME, startDate, new Date(), "foo",
Collections.emptyList(), "foo", "bar", null);
this.taskRepository.createTaskExecution(taskExecution);
assertThat(this.taskExplorer.getTaskExecutionCount()).as("Only one row is expected").isEqualTo(1);
this.applicationContext = getTaskApplication(1).run(new String[0]);
assertThat(waitForDBToBePopulated()).isTrue();
Page<TaskExecution> taskExecutions = this.taskExplorer.findAll(PageRequest.of(0, 10));
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
.isEqualTo(0);
assertThat(this.taskExplorer.getTaskExecution(1).getStartTime().getTime()).isEqualTo(startDate.getTime());
}
@Test
public void testWithNoTaskExecution() throws Exception {
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() -> {