diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index 3cc3b1da42..56137378d6 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -15,6 +15,7 @@ from django.core.exceptions import ValidationError # AWX from awx.api.versioning import reverse from awx.main.models.base import * # noqa +from awx.main.models.events import AdHocCommandEvent from awx.main.models.unified_jobs import * # noqa from awx.main.models.notifications import JobNotificationMixin, NotificationTemplate @@ -123,6 +124,10 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin): raise ValidationError(_('No argument passed to %s module.') % self.module_name) return module_args + @property + def event_class(self): + return AdHocCommandEvent + @property def passwords_needed_to_start(self): '''Return list of password field names needed to start the job.''' diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 5f136ee5b2..fcf77fd959 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -29,6 +29,7 @@ from awx.main.fields import ( ) from awx.main.managers import HostManager from awx.main.models.base import * # noqa +from awx.main.models.events import InventoryUpdateEvent from awx.main.models.unified_jobs import * # noqa from awx.main.models.mixins import ResourceMixin, TaskManagerInventoryUpdateMixin from awx.main.models.notifications import ( @@ -1590,6 +1591,10 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin, self.inventory_source.source_project.get_project_path(check_if_exists=False), self.source_path) + @property + def event_class(self): + return InventoryUpdateEvent + @property def task_impact(self): return 50 diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 6599b14811..a0be486102 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -26,6 +26,7 @@ from rest_framework.exceptions import ParseError # AWX from awx.api.versioning import reverse from awx.main.models.base import * # noqa +from awx.main.models.events import JobEvent, SystemJobEvent from awx.main.models.unified_jobs import * # noqa from awx.main.models.notifications import ( NotificationTemplate, @@ -512,6 +513,10 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana def get_ui_url(self): return urljoin(settings.TOWER_URL_BASE, "/#/jobs/{}".format(self.pk)) + @property + def event_class(self): + return JobEvent + @property def ask_diff_mode_on_launch(self): if self.job_template is not None: @@ -1165,6 +1170,10 @@ class SystemJob(UnifiedJob, SystemJobOptions, JobNotificationMixin): def get_ui_url(self): return urljoin(settings.TOWER_URL_BASE, "/#/management_jobs/{}".format(self.pk)) + @property + def event_class(self): + return SystemJobEvent + @property def task_impact(self): return 150 diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index a8578b97bd..c8687cab0b 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -18,6 +18,7 @@ from django.utils.timezone import now, make_aware, get_default_timezone # AWX from awx.api.versioning import reverse from awx.main.models.base import * # noqa +from awx.main.models.events import ProjectUpdateEvent from awx.main.models.notifications import ( NotificationTemplate, JobNotificationMixin, @@ -485,6 +486,10 @@ class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin, TaskManage websocket_data.update(dict(project_id=self.project.id)) return websocket_data + @property + def event_class(self): + return ProjectUpdateEvent + @property def task_impact(self): return 0 if self.job_type == 'run' else 20 diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 79431a5dec..ca9e07278e 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -893,6 +893,10 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique config.credentials.add(*job_creds) return config + @property + def event_class(self): + raise NotImplementedError() + @property def result_stdout_text(self): related = UnifiedJobDeprecatedStdout.objects.get(pk=self.pk) @@ -974,16 +978,11 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique # detect the length of all stdout for this UnifiedJob, and # if it exceeds settings.STDOUT_MAX_BYTES_DISPLAY bytes, # don't bother actually fetching the data - cursor.execute( - "select sum(length(stdout)) from {} where {}={}".format( - tablename + 'event', - related_name, - self.id - ) - ) - total_bytes = cursor.fetchone()[0] - if total_bytes > max_supported: - raise StdoutMaxBytesExceeded(total_bytes, max_supported) + total = self.event_class.objects.filter(**{related_name: self.id}).aggregate( + total=models.Sum(models.Func(models.F('stdout'), function='LENGTH')) + )['total'] + if total > max_supported: + raise StdoutMaxBytesExceeded(total, max_supported) cursor.copy_expert( "copy (select stdout from {} where {}={} order by start_line) to stdout".format(