From 0e68481a85540f273086bb4e6b79a280305f1d91 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 8 Sep 2016 11:48:11 -0400 Subject: [PATCH] consolidate workflow migration --- .../management/commands/run_task_system.py | 16 +----------- ...w_create.py => 0033_v310_add_workflows.py} | 9 ++++--- .../migrations/0034_auto_20160830_1716.py | 20 --------------- .../migrations/0035_auto_20160831_2008.py | 19 -------------- .../migrations/0036_auto_20160831_2052.py | 25 ------------------- awx/main/tasks.py | 7 +++--- 6 files changed, 10 insertions(+), 86 deletions(-) rename awx/main/migrations/{0033_v301_workflow_create.py => 0033_v310_add_workflows.py} (82%) delete mode 100644 awx/main/migrations/0034_auto_20160830_1716.py delete mode 100644 awx/main/migrations/0035_auto_20160831_2008.py delete mode 100644 awx/main/migrations/0036_auto_20160831_2052.py diff --git a/awx/main/management/commands/run_task_system.py b/awx/main/management/commands/run_task_system.py index 3e11b3511d..a03c38ffea 100644 --- a/awx/main/management/commands/run_task_system.py +++ b/awx/main/management/commands/run_task_system.py @@ -180,25 +180,20 @@ class WorkflowDAG(SimpleDAG): for index, n in enumerate(nodes): obj = n['node_object'] job = obj.job - print("\t\tExamining node %s job %s" % (obj, job)) if not job: - print("\t\tNo job for node %s" % obj) nodes_found.append(n) # Job is about to run or is running. Hold our horses and wait for # the job to finish. We can't proceed down the graph path until we # have the job result. elif job.status not in ['failed', 'error', 'successful']: - print("\t\tJob status not 'failed' 'error' nor 'successful' %s" % job.status) continue elif job.status in ['failed', 'error']: - print("\t\tJob status is failed or error %s" % job.status) children_failed = self.get_dependencies(obj, 'failure_nodes') children_always = self.get_dependencies(obj, 'always_nodes') children_all = children_failed + children_always nodes.extend(children_all) elif job.status in ['successful']: - print("\t\tJob status is successful %s" % job.status) children_success = self.get_dependencies(obj, 'success_nodes') nodes.extend(children_success) else: @@ -225,7 +220,7 @@ class WorkflowDAG(SimpleDAG): children_always = self.get_dependencies(obj, 'always_nodes') children_all = children_failed + children_always nodes.extend(children_all) - elif job.status in ['successful']: + elif job.status in ['successfult']: children_success = self.get_dependencies(obj, 'success_nodes') nodes.extend(children_success) else: @@ -261,22 +256,13 @@ def get_running_workflow_jobs(): def do_spawn_workflow_jobs(): workflow_jobs = get_running_workflow_jobs() - print("Set of workflow jobs to process %s" % workflow_jobs) for workflow_job in workflow_jobs: - print("Building the dag") dag = WorkflowDAG(workflow_job) - print("Imported the workflow job dag") - for n in dag.nodes: - print("\tWorkflow dag node %s" % n) - for f, to, label in dag.edges: - print("\tWorkflow dag edge <%s,%s,%s>" % (f, to, label)) spawn_nodes = dag.bfs_nodes_to_run() for spawn_node in spawn_nodes: - print("Spawning job %s" % spawn_node) # TODO: Inject job template template params as kwargs kv = {} job = spawn_node.unified_job_template.create_unified_job(**kv) - print("Started new job %s" % job.id) spawn_node.job = job spawn_node.save() result = job.signal_start(**kv) diff --git a/awx/main/migrations/0033_v301_workflow_create.py b/awx/main/migrations/0033_v310_add_workflows.py similarity index 82% rename from awx/main/migrations/0033_v301_workflow_create.py rename to awx/main/migrations/0033_v310_add_workflows.py index 258bdc797d..10f4879537 100644 --- a/awx/main/migrations/0033_v301_workflow_create.py +++ b/awx/main/migrations/0033_v310_add_workflows.py @@ -2,7 +2,9 @@ from __future__ import unicode_literals from django.db import migrations, models +import awx.main.models.notifications import django.db.models.deletion +import awx.main.models.workflow import awx.main.fields @@ -22,7 +24,7 @@ class Migration(migrations.Migration): options={ 'ordering': ('id',), }, - bases=('main.unifiedjob', models.Model), + bases=('main.unifiedjob', models.Model, awx.main.models.notifications.JobNotificationMixin, awx.main.models.workflow.WorkflowJobInheritNodesMixin), ), migrations.CreateModel( name='WorkflowJobTemplate', @@ -41,10 +43,11 @@ class Migration(migrations.Migration): ('modified', models.DateTimeField(default=None, editable=False)), ('always_nodes', models.ManyToManyField(related_name='parent_always_nodes', to='main.WorkflowNode', blank=True)), ('failure_nodes', models.ManyToManyField(related_name='parent_failure_nodes', to='main.WorkflowNode', blank=True)), - ('job', models.ForeignKey(related_name='workflow_node', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.UnifiedJob', null=True)), + ('job', models.ForeignKey(related_name='unified_job_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.UnifiedJob', null=True)), ('success_nodes', models.ManyToManyField(related_name='parent_success_nodes', to='main.WorkflowNode', blank=True)), ('unified_job_template', models.ForeignKey(related_name='unified_jt_workflow_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.UnifiedJobTemplate', null=True)), - ('workflow_job_template', models.ForeignKey(related_name='workflow_nodes', to='main.WorkflowJobTemplate')), + ('workflow_job', models.ForeignKey(related_name='workflow_job_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.WorkflowJob', null=True)), + ('workflow_job_template', models.ForeignKey(related_name='workflow_nodes', default=None, blank=True, to='main.WorkflowJobTemplate', null=True)), ], ), migrations.AddField( diff --git a/awx/main/migrations/0034_auto_20160830_1716.py b/awx/main/migrations/0034_auto_20160830_1716.py deleted file mode 100644 index a285a0d9dd..0000000000 --- a/awx/main/migrations/0034_auto_20160830_1716.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('main', '0033_v301_workflow_create'), - ] - - operations = [ - migrations.AlterField( - model_name='workflownode', - name='job', - field=models.ForeignKey(related_name='workflow_job_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.UnifiedJob', null=True), - ), - ] diff --git a/awx/main/migrations/0035_auto_20160831_2008.py b/awx/main/migrations/0035_auto_20160831_2008.py deleted file mode 100644 index 6297a29824..0000000000 --- a/awx/main/migrations/0035_auto_20160831_2008.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('main', '0034_auto_20160830_1716'), - ] - - operations = [ - migrations.AlterField( - model_name='workflownode', - name='workflow_job_template', - field=models.ForeignKey(related_name='workflow_nodes', default=None, blank=True, to='main.WorkflowJobTemplate', null=True), - ), - ] diff --git a/awx/main/migrations/0036_auto_20160831_2052.py b/awx/main/migrations/0036_auto_20160831_2052.py deleted file mode 100644 index ad16af0e4a..0000000000 --- a/awx/main/migrations/0036_auto_20160831_2052.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('main', '0035_auto_20160831_2008'), - ] - - operations = [ - migrations.AddField( - model_name='workflownode', - name='workflow_job', - field=models.ForeignKey(related_name='workflow_job_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.WorkflowJob', null=True), - ), - migrations.AlterField( - model_name='workflownode', - name='job', - field=models.ForeignKey(related_name='unified_job_nodes', on_delete=django.db.models.deletion.SET_NULL, default=None, blank=True, to='main.UnifiedJob', null=True), - ), - ] diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 713874ba3a..6c99350af5 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1674,12 +1674,11 @@ class RunWorkflowJob(BaseTask): # FIXME: Detect workflow run completion while True: dag = WorkflowDAG(instance) - print("Deciding if workflow is done") if dag.is_workflow_done(): # TODO: update with accurate finish status (i.e. canceled, error, etc.) - instance = self.update_model(instance.pk, status='success') - print("Workflow IS done") - return + instance = self.update_model(instance.pk, status='successful') + break time.sleep(1) + instance.socketio_emit_status(instance.status) # TODO: Handle cancel