diff --git a/awx/main/constants.py b/awx/main/constants.py index b2d62d5ec9..fbd783b968 100644 --- a/awx/main/constants.py +++ b/awx/main/constants.py @@ -41,6 +41,7 @@ STANDARD_INVENTORY_UPDATE_ENV = { } CAN_CANCEL = ('new', 'pending', 'waiting', 'running') ACTIVE_STATES = CAN_CANCEL +MINIMAL_EVENTS = set(['playbook_on_play_start', 'playbook_on_task_start', 'playbook_on_stats', 'EOF']) CENSOR_VALUE = '************' ENV_BLOCKLIST = frozenset( ( diff --git a/awx/main/models/events.py b/awx/main/models/events.py index 222eb22438..0a3cef78d1 100644 --- a/awx/main/models/events.py +++ b/awx/main/models/events.py @@ -17,6 +17,7 @@ from awx.api.versioning import reverse from awx.main import consumers from awx.main.managers import DeferJobCreatedManager from awx.main.fields import JSONField +from awx.main.constants import MINIMAL_EVENTS from awx.main.models.base import CreatedModifiedModel from awx.main.utils import ignore_inventory_computed_fields, camelcase_to_underscore @@ -57,9 +58,6 @@ def create_host_status_counts(event_data): return dict(host_status_counts) -MINIMAL_EVENTS = set(['playbook_on_play_start', 'playbook_on_task_start', 'playbook_on_stats', 'EOF']) - - def emit_event_detail(event): if settings.UI_LIVE_UPDATES_ENABLED is False and event.event not in MINIMAL_EVENTS: return diff --git a/awx/main/tasks.py b/awx/main/tasks.py index c9f0154561..d8697095a3 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -57,7 +57,7 @@ from receptorctl.socket_interface import ReceptorControl # AWX from awx import __version__ as awx_application_version -from awx.main.constants import PRIVILEGE_ESCALATION_METHODS, STANDARD_INVENTORY_UPDATE_ENV +from awx.main.constants import PRIVILEGE_ESCALATION_METHODS, STANDARD_INVENTORY_UPDATE_ENV, MINIMAL_EVENTS from awx.main.access import access_registry from awx.main.redact import UriCleaner from awx.main.models import ( @@ -1158,17 +1158,25 @@ class BaseTask(object): first_window_time = self.recent_event_timings[0] last_window_time = self.recent_event_timings[-1] - should_emit = bool( - # if 30the most recent websocket message was sent over 1 second ago - cpu_time - first_window_time > 1.0 - # if the very last websocket message came in over 1/30 seconds ago - or self.recent_event_timings.maxlen * (cpu_time - last_window_time) > 1.0 - # if the queue is not yet full - or (len(self.recent_event_timings) != self.recent_event_timings.maxlen) - ) + if event_data.get('event') in MINIMAL_EVENTS: + should_emit = True # always send some types like playbook_on_stats + if event_data.get('stdout') == '' and event_data['start_line'] == event_data['end_line']: + should_emit = False # exclude events with no output + else: + should_emit = any( + [ + # if 30the most recent websocket message was sent over 1 second ago + cpu_time - first_window_time > 1.0, + # if the very last websocket message came in over 1/30 seconds ago + self.recent_event_timings.maxlen * (cpu_time - last_window_time) > 1.0, + # if the queue is not yet full + len(self.recent_event_timings) != self.recent_event_timings.maxlen, + ] + ) logger.debug( - 'Event {} websocket send {}, queue {}, avg rate {}, last rate {}'.format( + 'Job {} event {} websocket send {}, queued: {}, rate - avg: {:.3f}, last: {:.3f}'.format( + self.instance.id, event_data.get('counter', 0), should_emit, len(self.recent_event_timings),