From f6ac7fb6d05a7c1e67a724cad882bfbd7b141677 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 17 Mar 2014 11:05:53 -0400 Subject: [PATCH] Fix up run task manager script to handle signals, fix up task cancel job, add restart handler for ubuntu --- awx/main/management/commands/run_task_system.py | 13 ++++++++++--- awx/main/tests/tasks.py | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/awx/main/management/commands/run_task_system.py b/awx/main/management/commands/run_task_system.py index 7d708e57c0..a940295d15 100644 --- a/awx/main/management/commands/run_task_system.py +++ b/awx/main/management/commands/run_task_system.py @@ -188,9 +188,9 @@ def rebuild_graph(message): dep.status = 'waiting' dep.save() waiting_tasks.insert(waiting_tasks.index(task), dep) - #if not hasattr(settings, 'CELERY_UNIT_TEST'): - task.status = 'waiting' - task.save() + if not hasattr(settings, 'UNIT_TEST_IGNORE_TASK_WAIT'): + task.status = 'waiting' + task.save() # Rebuild graph graph = SimpleDAG() @@ -248,6 +248,13 @@ def process_graph(graph, task_capacity): def run_taskmanager(command_port): ''' Receive task start and finish signals to rebuild a dependency graph and manage the actual running of tasks ''' + def shutdown_handler(): + def _handler(signum, frame): + signal.signal(signum, signal.SIG_DFL) + os.kill(os.getpid(), signum) + return _handler + signal.signal(signal.SIGINT, shutdown_handler()) + signal.signal(signal.SIGTERM, shutdown_handler()) paused = False task_capacity = get_system_task_capacity() command_context = zmq.Context() diff --git a/awx/main/tests/tasks.py b/awx/main/tests/tasks.py index 3cef95ef57..728674fb4f 100644 --- a/awx/main/tests/tasks.py +++ b/awx/main/tests/tasks.py @@ -646,10 +646,11 @@ class RunJobTest(BaseCeleryTest): self.assertFalse(job.cancel()) self.assertEqual(job.cancel_flag, False) self.assertFalse(job.passwords_needed_to_start) - self.build_args_callback = self._cancel_job_callback + job.cancel_flag = True + job.save() self.assertTrue(job.signal_start()) job = Job.objects.get(pk=job.pk) - self.check_job_result(job, 'canceled') + self.check_job_result(job, 'canceled', expect_stdout=False) self.assertEqual(job.cancel_flag, True) # Calling cancel afterwards just returns the cancel flag. self.assertTrue(job.cancel())