Java Code Examples for org.springframework.cloud.task.repository.TaskExecution#setErrorMessage()

The following examples show how to use org.springframework.cloud.task.repository.TaskExecution#setErrorMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskLifecycleListener.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
private TaskExecution invokeOnTaskEnd(TaskExecution taskExecution) {
	this.taskMetrics.onTaskEnd(taskExecution);
	TaskExecution listenerTaskExecution = getTaskExecutionCopy(taskExecution);
	if (this.taskExecutionListeners != null) {
		try {
			for (TaskExecutionListener taskExecutionListener : this.taskExecutionListeners) {
				taskExecutionListener.onTaskEnd(listenerTaskExecution);
			}
		}
		catch (Throwable listenerException) {
			String errorMessage = stackTraceToString(listenerException);
			if (StringUtils.hasText(listenerTaskExecution.getErrorMessage())) {
				errorMessage = String.format("%s :Task also threw this Exception: %s",
						errorMessage, listenerTaskExecution.getErrorMessage());
			}
			logger.error(errorMessage);
			listenerTaskExecution.setErrorMessage(errorMessage);
			this.listenerFailed = true;
		}
	}
	return listenerTaskExecution;
}
 
Example 2
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTaskExecutionNoParamMaxErrorMessageSize() {
	SimpleTaskRepository simpleTaskRepository = new SimpleTaskRepository(
			new TaskExecutionDaoFactoryBean(this.dataSource));
	simpleTaskRepository.setMaxErrorMessageSize(5);

	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
	expectedTaskExecution.setErrorMessage(
			new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			simpleTaskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length()).isEqualTo(5);
}
 
Example 3
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
private void verifyTaskRepositoryConstructor(Integer maxExitMessage,
		Integer maxErrorMessage, TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(taskRepository);
	expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1]));
	expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);

	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			taskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length())
			.isEqualTo(maxErrorMessage.intValue());
	assertThat(actualTaskExecution.getExitMessage().length())
			.isEqualTo(maxExitMessage.intValue());
}
 
Example 4
Source File: TaskLifecycleListener.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private TaskExecution invokeOnTaskError(TaskExecution taskExecution,
		Throwable throwable) {
	this.taskMetrics.onTaskFailed(throwable);
	TaskExecution listenerTaskExecution = getTaskExecutionCopy(taskExecution);
	if (this.taskExecutionListeners != null) {
		try {
			for (TaskExecutionListener taskExecutionListener : this.taskExecutionListeners) {
				taskExecutionListener.onTaskFailed(listenerTaskExecution, throwable);
			}
		}
		catch (Throwable listenerException) {
			this.listenerFailed = true;
			String errorMessage;
			if (StringUtils.hasText(listenerTaskExecution.getErrorMessage())) {
				errorMessage = String.format("%s :While handling " + "this error: %s",
						listenerException.getMessage(),
						listenerTaskExecution.getErrorMessage());
			}
			else {
				errorMessage = listenerTaskExecution.getErrorMessage();
			}
			logger.error(errorMessage);
			listenerTaskExecution.setErrorMessage(errorMessage);
			listenerTaskExecution.setExitCode(1);
		}

	}
	return listenerTaskExecution;
}
 
Example 5
Source File: MapTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
		String exitMessage, String errorMessage) {
	if (!this.taskExecutions.containsKey(executionId)) {
		throw new IllegalStateException(
				"Invalid TaskExecution, ID " + executionId + " not found.");
	}

	TaskExecution taskExecution = this.taskExecutions.get(executionId);
	taskExecution.setEndTime(endTime);
	taskExecution.setExitCode(exitCode);
	taskExecution.setExitMessage(exitMessage);
	taskExecution.setErrorMessage(errorMessage);
}
 
Example 6
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(this.taskRepository);
	expectedTaskExecution.setErrorMessage(
			new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);
	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			this.taskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length())
			.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
}