mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 19:10:07 -03:30
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:
commit
bdd41c70af
@ -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')
|
||||
|
||||
|
||||
@ -13,9 +13,10 @@ def test_ad_hoc_command_wait_successful(run_module, admin_user):
|
||||
command = AdHocCommand.objects.create(status='successful', started=now(), finished=now())
|
||||
result = run_module('tower_ad_hoc_command_wait', dict(command_id=command.id), admin_user)
|
||||
result.pop('invocation', None)
|
||||
result['elapsed'] = float(result['elapsed'])
|
||||
assert result.pop('finished', '')[:10] == str(command.finished)[:10]
|
||||
assert result.pop('started', '')[:10] == str(command.started)[:10]
|
||||
assert result == {"status": "successful", "changed": False, "elapsed": str(command.elapsed), "id": command.id}
|
||||
assert result == {"status": "successful", "changed": False, "elapsed": command.elapsed, "id": command.id}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@ -23,13 +24,14 @@ def test_ad_hoc_command_wait_failed(run_module, admin_user):
|
||||
command = AdHocCommand.objects.create(status='failed', started=now(), finished=now())
|
||||
result = run_module('tower_ad_hoc_command_wait', dict(command_id=command.id), admin_user)
|
||||
result.pop('invocation', None)
|
||||
result['elapsed'] = float(result['elapsed'])
|
||||
assert result.pop('finished', '')[:10] == str(command.finished)[:10]
|
||||
assert result.pop('started', '')[:10] == str(command.started)[:10]
|
||||
assert result == {
|
||||
"status": "failed",
|
||||
"failed": True,
|
||||
"changed": False,
|
||||
"elapsed": str(command.elapsed),
|
||||
"elapsed": command.elapsed,
|
||||
"id": command.id,
|
||||
"msg": "The ad hoc command - 1, failed",
|
||||
}
|
||||
|
||||
@ -13,9 +13,10 @@ def test_job_wait_successful(run_module, admin_user):
|
||||
job = Job.objects.create(status='successful', started=now(), finished=now())
|
||||
result = run_module('tower_job_wait', dict(job_id=job.id), admin_user)
|
||||
result.pop('invocation', None)
|
||||
result['elapsed'] = float(result['elapsed'])
|
||||
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
|
||||
assert result.pop('started', '')[:10] == str(job.started)[:10]
|
||||
assert result == {"status": "successful", "changed": False, "elapsed": str(job.elapsed), "id": job.id}
|
||||
assert result == {"status": "successful", "changed": False, "elapsed": job.elapsed, "id": job.id}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@ -23,9 +24,10 @@ def test_job_wait_failed(run_module, admin_user):
|
||||
job = Job.objects.create(status='failed', started=now(), finished=now())
|
||||
result = run_module('tower_job_wait', dict(job_id=job.id), admin_user)
|
||||
result.pop('invocation', None)
|
||||
result['elapsed'] = float(result['elapsed'])
|
||||
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
|
||||
assert result.pop('started', '')[:10] == str(job.started)[:10]
|
||||
assert result == {"status": "failed", "failed": True, "changed": False, "elapsed": str(job.elapsed), "id": job.id, "msg": "Job with id 1 failed"}
|
||||
assert result == {"status": "failed", "failed": True, "changed": False, "elapsed": job.elapsed, "id": job.id, "msg": "Job with id 1 failed"}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user