diff --git a/awx/api/views.py b/awx/api/views.py index 7d1a855ed7..57f46189ba 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2967,21 +2967,7 @@ class JobJobTasksList(BaseJobEventsList): return ({'detail': 'Parent event not found.'}, -1, status.HTTP_404_NOT_FOUND) parent_task = parent_task[0] - # Some events correspond to a playbook or task starting up, - # and these are what we're interested in here. - STARTING_EVENTS = ('playbook_on_task_start', 'playbook_on_setup') - - # We need to pull information about each start event. - # - # This is super tricky, because this table has a one-to-many - # relationship with itself (parent-child), and we're getting - # information for an arbitrary number of children. This means we - # need stats on grandchildren, sorted by child. - queryset = (JobEvent.objects.filter(parent__parent=parent_task, - parent__event__in=STARTING_EVENTS) - .values('parent__id', 'event', 'changed') - .annotate(num=Count('event')) - .order_by('parent__id')) + queryset = JobEvent.start_event_queryset(parent_task) # The data above will come back in a list, but we are going to # want to access it based on the parent id, so map it into a diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index ac67bf8d67..552a30a285 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -1206,6 +1206,30 @@ class JobEvent(CreatedModifiedModel): job.inventory.update_computed_fields() emit_websocket_notification('/socket.io/jobs', 'summary_complete', dict(unified_job_id=job.id)) + @property + def STARTING_EVENTS(): + return ('playbook_on_task_start', 'playbook_on_setup') + + @classmethod + def get_startevent_queryset(cls, parent_task, ordering=None): + ''' + We need to pull information about each start event. + + This is super tricky, because this table has a one-to-many + relationship with itself (parent-child), and we're getting + information for an arbitrary number of children. This means we + need stats on grandchildren, sorted by child. + ''' + qs = (JobEvent.objects.filter(parent__parent=parent_task, + parent__event__in=STARTING_EVENTS) + .values('parent__id', 'event', 'changed') + .annotate(num=Count('event')) + .order_by('parent__id')) + if ordering is not None: + qs = qs.order_by(ordering) + return qs + + class SystemJobOptions(BaseModel): ''' Common fields for SystemJobTemplate and SystemJob.