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
This commit is contained in:
David Moreau Simard 2020-09-16 21:04:24 -04:00
parent a8c3345575
commit dda3e43bc8
No known key found for this signature in database
GPG Key ID: 7D4729EC4E64E8B7

View File

@ -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: