diff --git a/java/code/src/com/redhat/rhn/taskomatic/task/MinionActionExecutor.java b/java/code/src/com/redhat/rhn/taskomatic/task/MinionActionExecutor.java index c17da071458c..1dc8bc7dbf6d 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/task/MinionActionExecutor.java +++ b/java/code/src/com/redhat/rhn/taskomatic/task/MinionActionExecutor.java @@ -111,7 +111,8 @@ public void execute(JobExecutionContext context) { // HACK: it is possible that this Taskomatic task triggered before the corresponding Action was really // COMMITted in the database. Wait for some minutes checking if it appears int waitedTime = 0; - while (countQueuedServerActions(action) == 0 && waitedTime < ACTION_DATABASE_GRACE_TIME) { + while (countQueuedServerActions(action) == 0 && waitedTime < ACTION_DATABASE_GRACE_TIME && + !allServerActionsFinished(action)) { action = ActionFactory.lookupById(actionId); try { Thread.sleep(ACTION_DATABASE_POLL_TIME); @@ -128,6 +129,14 @@ public void execute(JobExecutionContext context) { return; } + // Instead of putting the thread to sleep in the loop above, checking if all server actions have already + // finished (they might have been manually canceled, for example) will prevent blocking the Taskomatic for + // actions that will never appear in the database. + if (allServerActionsFinished(action)) { + log.warn("All server actions for action {} are finished. Skipping it.", actionId); + return; + } + if (countQueuedServerActions(action) == 0) { log.error("Action with id={} has no server with status QUEUED", actionId); return; @@ -192,4 +201,13 @@ private long countQueuedServerActions(Action action) { .filter(serverAction -> ActionFactory.STATUS_QUEUED.equals(serverAction.getStatus())) .count(); } + + private boolean allServerActionsFinished(Action action) { + return action != null && + !CollectionUtils.isEmpty(action.getServerActions()) && + action.getServerActions().stream().allMatch(serverAction -> + ActionFactory.STATUS_FAILED.equals(serverAction.getStatus()) || + ActionFactory.STATUS_COMPLETED.equals(serverAction.getStatus()) + ); + } } diff --git a/java/spacewalk-java.changes.welder.fix-taskomatic-blocking b/java/spacewalk-java.changes.welder.fix-taskomatic-blocking new file mode 100644 index 000000000000..02faaf0a58c5 --- /dev/null +++ b/java/spacewalk-java.changes.welder.fix-taskomatic-blocking @@ -0,0 +1 @@ +- Fix action executor to prevent blocking Taskomatic for actions that are already finished (bsc#1214121)