From 6e22460f1ed52f43e80081a8fea21feaa14924e5 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 20 Oct 2016 15:18:05 -0400 Subject: [PATCH] Add scm revision to the job model This also cleans up flake8 issues --- awx/api/serializers.py | 2 +- awx/main/migrations/0043_v310_scm_revision.py | 6 ++++ awx/main/models/jobs.py | 9 ++++++ awx/main/models/projects.py | 3 -- awx/main/tasks.py | 4 ++- awx/settings/defaults.py | 29 +++++++++---------- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 861e245a75..5053c5aa96 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1930,7 +1930,7 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer): fields = ('*', 'job_template', 'passwords_needed_to_start', 'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_skip_tags_on_launch', 'ask_job_type_on_launch', 'ask_inventory_on_launch', 'ask_credential_on_launch', - 'allow_simultaneous', 'artifacts',) + 'allow_simultaneous', 'artifacts', 'scm_revision',) def get_related(self, obj): res = super(JobSerializer, self).get_related(obj) diff --git a/awx/main/migrations/0043_v310_scm_revision.py b/awx/main/migrations/0043_v310_scm_revision.py index 7936d8b0a1..08db6be47e 100644 --- a/awx/main/migrations/0043_v310_scm_revision.py +++ b/awx/main/migrations/0043_v310_scm_revision.py @@ -21,4 +21,10 @@ class Migration(migrations.Migration): name='job_type', field=models.CharField(default=b'check', max_length=64, choices=[(b'run', 'Run'), (b'check', 'Check')]), ), + migrations.AddField( + model_name='job', + name='scm_revision', + field=models.CharField(default=b'', editable=False, max_length=1024, blank=True, help_text='The SCM Revision from the Project used for this job, if available', verbose_name='SCM Revision'), + ), + ] diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 9c216fc526..1f11e5dee9 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -559,6 +559,15 @@ class Job(UnifiedJob, JobOptions, JobNotificationMixin): default={}, editable=False, ) + scm_revision = models.CharField( + max_length=1024, + blank=True, + default='', + editable=False, + verbose_name=_('SCM Revision'), + help_text=_('The SCM Revision from the Project used for this job, if available'), + ) + @classmethod def _get_parent_field_name(cls): diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index d96bcec98b..5686716d73 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -7,9 +7,6 @@ import os import re import urlparse -# Celery -from celery import group, chord - # Django from django.conf import settings from django.db import models diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 456ad6293c..f834e32ff3 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -919,7 +919,7 @@ class RunJob(BaseTask): if job.project: extra_vars.update({ 'tower_project_revision': job.project.scm_revision, - }) + }) if job.job_template: extra_vars.update({ 'tower_job_template_id': job.job_template.pk, @@ -1004,6 +1004,8 @@ class RunJob(BaseTask): project_update_task = local_project_sync._get_task_class() try: project_update_task().run(local_project_sync.id) + job.scm_revision = job.project.scm_revision + job.save() except Exception: job.status = 'failed' job.job_explanation = 'Previous Task Failed: {"job_type": "%s", "job_name": "%s", "job_id": "%s"}' % \ diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 11095a61f5..d0aebcefa1 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -9,7 +9,6 @@ import djcelery from datetime import timedelta from kombu import Queue, Exchange -from kombu.common import Broadcast # Update this module's local settings from the global settings module. from django.conf import global_settings @@ -361,20 +360,20 @@ CELERY_QUEUES = ( ) CELERY_ROUTES = {'awx.main.tasks.run_job': {'queue': 'jobs', 'routing_key': 'jobs'}, - 'awx.main.tasks.run_project_update': {'queue': 'jobs', - 'routing_key': 'jobs'}, - 'awx.main.tasks.run_inventory_update': {'queue': 'jobs', - 'routing_key': 'jobs'}, - 'awx.main.tasks.run_ad_hoc_command': {'queue': 'jobs', - 'routing_key': 'jobs'}, - 'awx.main.tasks.run_system_job': {'queue': 'jobs', - 'routing_key': 'jobs'}, - 'awx.main.scheduler.tasks.run_job_launch': {'queue': 'scheduler', - 'routing_key': 'scheduler.job.launch'}, - 'awx.main.scheduler.tasks.run_job_complete': {'queue': 'scheduler', - 'routing_key': 'scheduler.job.complete'}, - 'awx.main.tasks.cluster_node_heartbeat': {'queue': 'default', - 'routing_key': 'cluster.heartbeat'}, + 'awx.main.tasks.run_project_update': {'queue': 'jobs', + 'routing_key': 'jobs'}, + 'awx.main.tasks.run_inventory_update': {'queue': 'jobs', + 'routing_key': 'jobs'}, + 'awx.main.tasks.run_ad_hoc_command': {'queue': 'jobs', + 'routing_key': 'jobs'}, + 'awx.main.tasks.run_system_job': {'queue': 'jobs', + 'routing_key': 'jobs'}, + 'awx.main.scheduler.tasks.run_job_launch': {'queue': 'scheduler', + 'routing_key': 'scheduler.job.launch'}, + 'awx.main.scheduler.tasks.run_job_complete': {'queue': 'scheduler', + 'routing_key': 'scheduler.job.complete'}, + 'awx.main.tasks.cluster_node_heartbeat': {'queue': 'default', + 'routing_key': 'cluster.heartbeat'}, } CELERYBEAT_SCHEDULE = {