Updated notifications.py

Fixed the customized notification returning incorrect values for host_status_counts

Update notifications.py

Removed if condition

Added exception handling

A nitpick
This commit is contained in:
Saurabh Thakre 2021-02-18 12:24:14 +00:00
parent 753749d2b4
commit 6aca9d80bb

View File

@ -383,12 +383,17 @@ class JobNotificationMixin(object):
and a url to the job run."""
job_context = {'host_status_counts': {}}
summary = None
if hasattr(self, 'job_host_summaries'):
summary = self.job_host_summaries.first()
if summary:
from awx.api.serializers import JobHostSummarySerializer
summary_data = JobHostSummarySerializer(summary).to_representation(summary)
job_context['host_status_counts'] = summary_data
try:
has_event_property = any([f for f in self.event_class._meta.fields if f.name == 'event'])
except NotImplementedError:
has_event_property = False
if has_event_property:
qs = self.get_event_queryset()
if qs:
event = qs.only('event_data').filter(event='playbook_on_stats').first()
if event:
summary = event.get_host_status_counts()
job_context['host_status_counts'] = summary
context = {
'job': job_context,
'job_friendly_name': self.get_notification_friendly_name(),