diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java index cadb8598f2f..cb6330437a8 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskManagerQuartzImpl.java @@ -481,6 +481,7 @@ public void resumeTask(Task task, OperationResult parentResult) throws ObjectNot result.recordFatalError(message); return; } + clearTaskOperationResult(task, parentResult); // see a note on scheduleTaskNow resumeOrUnpauseTask(task, result); } @@ -1350,9 +1351,16 @@ public void deleteNode(String nodeOid, OperationResult result) throws SchemaExce @Override public void scheduleTaskNow(Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException { + /* + * Note: we clear task operation result because this is what a user would generally expect when re-running a task + * (MID-1920). We do NOT do that on each task run e.g. to have an ability to see last task execution status + * during a next task run. (When the interval between task runs is too short, e.g. for live sync tasks.) + */ if (task.isClosed()) { + clearTaskOperationResult(task, parentResult); executionManager.reRunClosedTask(task, parentResult); } else if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) { + clearTaskOperationResult(task, parentResult); scheduleRunnableTaskNow(task, parentResult); } else { String message = "Task " + task + " cannot be run now, because it is not in RUNNABLE nor CLOSED state."; @@ -1362,6 +1370,12 @@ public void scheduleTaskNow(Task task, OperationResult parentResult) throws Sche } } + private void clearTaskOperationResult(Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException { + OperationResult emptyTaskResult = new OperationResult("run"); + emptyTaskResult.setStatus(OperationResultStatus.IN_PROGRESS); + task.setResultImmediate(emptyTaskResult, parentResult); + } + public void scheduleRunnableTaskNow(Task task, OperationResult parentResult) { executionManager.scheduleRunnableTaskNow(task, parentResult); }