Merge pull request #9847 from fosterseth/fix_t4922_job_elapsed_time_incorrect

Fix elapsed time on job showing incorrect value

SUMMARY

Elapsed time would always stay at zero

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME


API

AWX VERSION

awx: 18.0.0

Reviewed-by: Seth Foster <None>
Reviewed-by: Ryan Petrello <None>
Reviewed-by: Alan Rominger <arominge@redhat.com>
Reviewed-by: Jeff Bradberry <None>
This commit is contained in:
softwarefactory-project-zuul[bot]
2021-04-12 14:35:04 +00:00
committed by GitHub
3 changed files with 16 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
# Python
from io import StringIO
import datetime
import decimal
import codecs
import json
import logging
@@ -842,15 +843,16 @@ class UnifiedJob(
if 'finished' not in update_fields:
update_fields.append('finished')
dq = decimal.Decimal('1.000')
if self.elapsed is None:
self.elapsed = decimal.Decimal(0.0).quantize(dq)
# If we have a start and finished time, and haven't already calculated
# out the time that elapsed, do so.
if self.started and self.finished and not self.elapsed:
if self.started and self.finished and self.elapsed == 0.0:
td = self.finished - self.started
elapsed = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / (10 ** 6 * 1.0)
else:
elapsed = 0.0
if self.elapsed != elapsed:
self.elapsed = str(elapsed)
elapsed = decimal.Decimal(td.total_seconds())
self.elapsed = elapsed.quantize(dq)
if 'elapsed' not in update_fields:
update_fields.append('elapsed')