StartTime is now honored for TaskExecution
regardless if they were created before or during task execution. resolves #861
This commit is contained in:
@@ -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.
|
||||
@@ -277,8 +277,9 @@ public class TaskLifecycleListener
|
||||
Assert.isNull(taskExecution.getEndTime(),
|
||||
String.format("Invalid TaskExecution, ID %s task is already complete",
|
||||
this.taskProperties.getExecutionid()));
|
||||
Date startDate = (taskExecution.getStartTime() == null) ? new Date() : taskExecution.getStartTime();
|
||||
this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(),
|
||||
this.taskNameResolver.getTaskName(), new Date(), args,
|
||||
this.taskNameResolver.getTaskName(), startDate, args,
|
||||
this.taskProperties.getExternalExecutionId(), this.taskProperties.getParentExecutionId());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -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;
|
||||
@@ -185,6 +186,27 @@ public class TaskStartTests {
|
||||
assertThat(this.taskExplorer.getTaskExecution(1).getTaskName()).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(() -> {
|
||||
|
||||
Reference in New Issue
Block a user