mirror of
https://github.com/ansible/awx.git
synced 2026-02-14 17:50:02 -03:30
Merge pull request #5610 from thedoubl3j/canceled_jobs
Added canceled_on field to unified_jobs model Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -117,7 +117,7 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
|
'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'),
|
||||||
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed',),
|
'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed',),
|
||||||
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'),
|
'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'),
|
||||||
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed', 'type'),
|
'job': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'elapsed', 'type', 'canceled_on'),
|
||||||
'job_template': DEFAULT_SUMMARY_FIELDS,
|
'job_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
'workflow_job_template': DEFAULT_SUMMARY_FIELDS,
|
'workflow_job_template': DEFAULT_SUMMARY_FIELDS,
|
||||||
'workflow_job': DEFAULT_SUMMARY_FIELDS,
|
'workflow_job': DEFAULT_SUMMARY_FIELDS,
|
||||||
@@ -125,7 +125,7 @@ SUMMARIZABLE_FK_FIELDS = {
|
|||||||
'workflow_approval': DEFAULT_SUMMARY_FIELDS + ('timeout',),
|
'workflow_approval': DEFAULT_SUMMARY_FIELDS + ('timeout',),
|
||||||
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
'schedule': DEFAULT_SUMMARY_FIELDS + ('next_run',),
|
||||||
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('unified_job_type',),
|
'unified_job_template': DEFAULT_SUMMARY_FIELDS + ('unified_job_type',),
|
||||||
'last_job': DEFAULT_SUMMARY_FIELDS + ('finished', 'status', 'failed', 'license_error'),
|
'last_job': DEFAULT_SUMMARY_FIELDS + ('finished', 'status', 'failed', 'license_error', 'canceled_on'),
|
||||||
'last_job_host_summary': DEFAULT_SUMMARY_FIELDS + ('failed',),
|
'last_job_host_summary': DEFAULT_SUMMARY_FIELDS + ('failed',),
|
||||||
'last_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'last_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
'current_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
'current_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed', 'license_error'),
|
||||||
@@ -719,7 +719,7 @@ class UnifiedJobSerializer(BaseSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = UnifiedJob
|
model = UnifiedJob
|
||||||
fields = ('*', 'unified_job_template', 'launch_type', 'status',
|
fields = ('*', 'unified_job_template', 'launch_type', 'status',
|
||||||
'failed', 'started', 'finished', 'elapsed', 'job_args',
|
'failed', 'started', 'finished', 'canceled_on', 'elapsed', 'job_args',
|
||||||
'job_cwd', 'job_env', 'job_explanation',
|
'job_cwd', 'job_env', 'job_explanation',
|
||||||
'execution_node', 'controller_node',
|
'execution_node', 'controller_node',
|
||||||
'result_traceback', 'event_processing_finished')
|
'result_traceback', 'event_processing_finished')
|
||||||
@@ -2823,7 +2823,7 @@ class JobTemplateMixin(object):
|
|||||||
# .only('id', 'status', 'finished', 'polymorphic_ctype_id')
|
# .only('id', 'status', 'finished', 'polymorphic_ctype_id')
|
||||||
optimized_qs = uj_qs.non_polymorphic()
|
optimized_qs = uj_qs.non_polymorphic()
|
||||||
return [{
|
return [{
|
||||||
'id': x.id, 'status': x.status, 'finished': x.finished,
|
'id': x.id, 'status': x.status, 'finished': x.finished, 'canceled_on': x.canceled_on,
|
||||||
# Make type consistent with API top-level key, for instance workflow_job
|
# Make type consistent with API top-level key, for instance workflow_job
|
||||||
'type': x.get_real_instance_class()._meta.verbose_name.replace(' ', '_')
|
'type': x.get_real_instance_class()._meta.verbose_name.replace(' ', '_')
|
||||||
} for x in optimized_qs[:10]]
|
} for x in optimized_qs[:10]]
|
||||||
|
|||||||
18
awx/main/migrations/0102_v370_unifiedjob_canceled.py
Normal file
18
awx/main/migrations/0102_v370_unifiedjob_canceled.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 2.2.4 on 2019-11-25 20:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0101_v370_generate_new_uuids_for_iso_nodes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='unifiedjob',
|
||||||
|
name='canceled_on',
|
||||||
|
field=models.DateTimeField(db_index=True, default=None, editable=False, help_text='The date and time when the cancel request was sent.', null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -630,6 +630,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
help_text=_("The date and time the job finished execution."),
|
help_text=_("The date and time the job finished execution."),
|
||||||
db_index=True,
|
db_index=True,
|
||||||
)
|
)
|
||||||
|
canceled_on = models.DateTimeField(
|
||||||
|
null=True,
|
||||||
|
default=None,
|
||||||
|
editable=False,
|
||||||
|
help_text=_("The date and time when the cancel request was sent."),
|
||||||
|
db_index=True,
|
||||||
|
)
|
||||||
elapsed = models.DecimalField(
|
elapsed = models.DecimalField(
|
||||||
max_digits=12,
|
max_digits=12,
|
||||||
decimal_places=3,
|
decimal_places=3,
|
||||||
@@ -834,6 +841,11 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
if 'unified_job_template' not in update_fields:
|
if 'unified_job_template' not in update_fields:
|
||||||
update_fields.append('unified_job_template')
|
update_fields.append('unified_job_template')
|
||||||
|
|
||||||
|
if self.cancel_flag and not self.canceled_on:
|
||||||
|
# Record the 'canceled' time.
|
||||||
|
self.canceled_on = now()
|
||||||
|
if 'canceled_on' not in update_fields:
|
||||||
|
update_fields.append('canceled_on')
|
||||||
# Okay; we're done. Perform the actual save.
|
# Okay; we're done. Perform the actual save.
|
||||||
result = super(UnifiedJob, self).save(*args, **kwargs)
|
result = super(UnifiedJob, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ def test_summary_fields_recent_jobs(job_template, admin_user, get):
|
|||||||
'id': job.id,
|
'id': job.id,
|
||||||
'status': 'failed',
|
'status': 'failed',
|
||||||
'finished': job.finished,
|
'finished': job.finished,
|
||||||
|
'canceled_on': None,
|
||||||
'type': 'job'
|
'type': 'job'
|
||||||
} for job in jobs[-10:][::-1]]
|
} for job in jobs[-10:][::-1]]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user