remove job to jt allow_simultaneous dependency

* Foreshadowing of what's to come with the task manager. When deciding
on what job to run in our task manager, we can't depend on job template
fields. Otherwise, this would cost us a query.
This commit is contained in:
Chris Meyers 2016-09-29 16:17:05 -04:00
parent 1a60dd89bd
commit 9cafebd8db
3 changed files with 26 additions and 6 deletions

View File

@ -1953,7 +1953,8 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
model = Job
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')
'ask_job_type_on_launch', 'ask_inventory_on_launch', 'ask_credential_on_launch',
'allow_simultaneous',)
def get_related(self, obj):
res = super(JobSerializer, self).get_related(obj)

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0036_v310_remove_tower_settings'),
]
operations = [
migrations.AddField(
model_name='job',
name='allow_simultaneous',
field=models.BooleanField(default=False),
),
]

View File

@ -138,6 +138,9 @@ class JobOptions(BaseModel):
become_enabled = models.BooleanField(
default=False,
)
allow_simultaneous = models.BooleanField(
default=False,
)
extra_vars_dict = VarsDictProperty('extra_vars', True)
@ -236,9 +239,6 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
read_role = ImplicitRoleField(
parent_role=['project.organization.auditor_role', 'inventory.organization.auditor_role', 'execute_role', 'admin_role'],
)
allow_simultaneous = models.BooleanField(
default=False,
)
@classmethod
@ -251,7 +251,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
'playbook', 'credential', 'cloud_credential', 'network_credential', 'forks', 'schedule',
'limit', 'verbosity', 'job_tags', 'extra_vars', 'launch_type',
'force_handlers', 'skip_tags', 'start_at_task', 'become_enabled',
'labels', 'survey_passwords']
'labels', 'survey_passwords', 'allow_simultaneous',]
def resource_validation_data(self):
'''
@ -616,7 +616,7 @@ class Job(UnifiedJob, JobOptions, JobNotificationMixin):
if obj.job_template is not None and obj.inventory is not None:
if obj.job_template == self.job_template and \
obj.inventory == self.inventory:
if self.job_template.allow_simultaneous:
if self.allow_simultaneous:
return False
if obj.launch_type == 'callback' and self.launch_type == 'callback' and \
obj.limit != self.limit: