Skip to content

Commit

Permalink
core: use PlaybookStatus to determie playbook has ended
Browse files Browse the repository at this point in the history
Instead of parsing the current event we can reuse the same logic as used
for async playbooks, check the "status" artifact to see if ansible is
stil running or not, and check if all events has been processed
  • Loading branch information
michalskrivanek committed Jul 22, 2022
1 parent 39908a8 commit c91eb65
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ public AnsibleRunnerClient() {
}

public Boolean playHasEnded(String uuid, int lastEventId) {
String lastEvent = getEventFileName(uuid, lastEventId);
if (lastEvent == null) {
return false;
}
String jobEvents = getJobEventsDir(uuid);
File lastEventFile = new File(jobEvents + lastEvent);
String res = "";
try {
res = Files.readString(lastEventFile.toPath());
} catch (IOException e) {
return false;
}
return res.contains("playbook_on_stats");
// get current status, but new events might have appeared since last processing
PlaybookStatus currentPlaybookStatus = getPlaybookStatus(uuid);
String msg = currentPlaybookStatus.getMsg();
return !msg.equalsIgnoreCase("running") && lastEventId <= getTotalEvents(uuid);
}

public AnsibleReturnValue artifactHandler(UUID uuid, int lastEventID, int timeout, BiConsumer<String, String> fn)
Expand Down

0 comments on commit c91eb65

Please sign in to comment.