From 3b252680e75caa5cb4b92aa2869e584e6e2b995d Mon Sep 17 00:00:00 2001 From: Glenn Renfro Date: Mon, 22 Feb 2016 13:39:02 -0500 Subject: [PATCH] SCT-82 Exit Code needs to be null while task is running TaskLifecycleListener will set a TaskExecution's exitCode to null upon taskStart in the repository. Only at the end of the execution will it store the exitCode. resolves spring-cloud/spring-cloud-task#82 --- .../cloud/task/listener/TaskLifecycleListener.java | 2 +- .../cloud/task/repository/TaskExecution.java | 8 ++++---- .../cloud/task/repository/dao/JdbcTaskExecutionDao.java | 2 +- .../cloud/task/listener/TaskLifecycleListenerTests.java | 9 ++++++--- spring-cloud-task-docs/src/main/asciidoc/features.adoc | 4 ++++ 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java index ea8730f1..b937008d 100644 --- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java @@ -160,7 +160,7 @@ public class TaskLifecycleListener implements ApplicationListener(); } - public TaskExecution(long executionId, int exitCode, String taskName, + public TaskExecution(long executionId, Integer exitCode, String taskName, Date startTime, Date endTime, String exitMessage, List parameters) { @@ -87,11 +87,11 @@ public class TaskExecution { return executionId; } - public int getExitCode() { + public Integer getExitCode() { return exitCode; } - public void setExitCode(int exitCode) { + public void setExitCode(Integer exitCode) { this.exitCode = exitCode; } diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java index 90b85fa9..2b5ef264 100644 --- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java @@ -324,7 +324,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao { public TaskExecution mapRow(ResultSet rs, int rowNum) throws SQLException { long id = rs.getLong("TASK_EXECUTION_ID"); TaskExecution taskExecution=new TaskExecution(id, - rs.getInt("EXIT_CODE"), + (Integer) rs.getObject("EXIT_CODE"), rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"), rs.getTimestamp("END_TIME"), diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java index 1f5bd266..933bd75c 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java @@ -17,6 +17,7 @@ package org.springframework.cloud.task.listener; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -75,14 +76,14 @@ public class TaskLifecycleListenerTests { @Test public void testTaskCreate() { context.refresh(); - verifyTaskExecution(0, false, 0, null); + verifyTaskExecution(0, false, null, null); } @Test public void testTaskCreateWithArgs() { context.register(ArgsConfiguration.class); context.refresh(); - verifyTaskExecution(2, false, 0, null); + verifyTaskExecution(2, false, null, null); } @Test @@ -113,7 +114,7 @@ public class TaskLifecycleListenerTests { return writer.toString(); } - private void verifyTaskExecution(int numberOfParams, boolean update, int exitCode, Throwable exception) { + private void verifyTaskExecution(int numberOfParams, boolean update, Integer exitCode, Throwable exception) { this.taskExplorer = context.getBean(TaskExplorer.class); Sort sort = new Sort("id"); @@ -137,9 +138,11 @@ public class TaskLifecycleListenerTests { if(update) { assertTrue(taskExecution.getEndTime().getTime() >= taskExecution.getStartTime().getTime()); + assertNotNull(taskExecution.getExitCode()); } else { assertNull(taskExecution.getEndTime()); + assertNull(taskExecution.getExitCode()); } assertEquals("testTask", taskExecution.getTaskName()); diff --git a/spring-cloud-task-docs/src/main/asciidoc/features.adoc b/spring-cloud-task-docs/src/main/asciidoc/features.adoc index ac77f912..f2b35941 100644 --- a/spring-cloud-task-docs/src/main/asciidoc/features.adoc +++ b/spring-cloud-task-docs/src/main/asciidoc/features.adoc @@ -98,6 +98,10 @@ map uncaught exceptions to exit codes. This allows you to be able to indicate a level what went wrong. Also, by mapping exit codes in this manor, Spring Cloud Task will record the exit code returned. +NOTE: While the task is running the exit code will be stored as a null in the repository. +Once complete the appropriate exit code will be stored based on the guidelines enumerated +above. + [[features-configuration]] == Configuration