From dda3e43bc8b999864ed6bd366f819f532d49511d Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Wed, 16 Sep 2020 21:04:24 -0400 Subject: [PATCH] callback: set a more accurate start date for results Because we always set the started date of results as the beginning of the task, each host result for the task apparently took a little bit longer than the previous to complete because they were running one after the other. By storing a timestamp at the end of a result, we can use it as the start date of the new result. While imperfect, it will be far more accurate than relying on the task started date to calculate the duration of each result. Fixes: https://github.com/ansible-community/ara/issues/173 Change-Id: Iade5dc3ba35272ac7993a114d06bbefcd096d677 --- ara/plugins/callback/ara_default.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ara/plugins/callback/ara_default.py b/ara/plugins/callback/ara_default.py index cc258296..e11da6d1 100644 --- a/ara/plugins/callback/ara_default.py +++ b/ara/plugins/callback/ara_default.py @@ -163,6 +163,7 @@ class CallbackModule(CallbackBase): self.ignored_files = [] self.result = None + self.result_timestamp = None self.task = None self.play = None self.playbook = None @@ -418,7 +419,7 @@ class CallbackModule(CallbackBase): play=self.task["play"], content=results, status=status, - started=self.task["started"], + started=self.result_timestamp or self.task["started"], ended=datetime.datetime.now().isoformat(), changed=result._result.get("changed", False), # Note: ignore_errors might be None instead of a boolean @@ -428,6 +429,11 @@ class CallbackModule(CallbackBase): if self.task["action"] in ["setup", "gather_facts"] and "ansible_facts" in results: self.client.patch("/api/v1/hosts/%s" % host["id"], facts=results["ansible_facts"]) + # The last thing that runs before the next result is loaded: use that as start date for the next result. + # If it's the first result, the started value of the task would be used as start date instead. + # See: https://github.com/ansible-community/ara/issues/173 + self.result_timestamp = datetime.datetime.now().isoformat() + def _load_stats(self, stats): hosts = sorted(stats.processed.keys()) for hostname in hosts: