Skip to content

Commit

Permalink
Fix action executor to prevent blocking Taskomatic for actions that a…
Browse files Browse the repository at this point in the history
…re already finished
  • Loading branch information
wweellddeerr committed Aug 16, 2023
1 parent 327a079 commit 07c540e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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())
);
}
}
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.welder.fix-taskomatic-blocking
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix action executor to prevent blocking Taskomatic for actions that are already finished (bsc#1214121)

0 comments on commit 07c540e

Please sign in to comment.