]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Only create the period watch task if there is a watch in the stack
authorAngus Salkeld <asalkeld@redhat.com>
Wed, 17 Jul 2013 02:46:59 +0000 (12:46 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Fri, 19 Jul 2013 05:00:19 +0000 (15:00 +1000)
This prevents unneccessary greentheads polling the db.

bug 1202031
Change-Id: I065955d03df543df40af285f87a7fd3dfa779413

heat/engine/service.py
heat/tests/test_engine_service.py

index 0a065d107ca724ed14df762dae0f23a2ab2bb2c0..b4d9053f85ebe91af6187b1f46ed1ed314893621 100644 (file)
@@ -95,9 +95,12 @@ class EngineService(service.Service):
         """
         pass
 
-    def _start_watch_task(self, stack_id):
-        self._timer_in_thread(stack_id, self._periodic_watcher_task,
-                              sid=stack_id)
+    def _start_watch_task(self, stack_id, cnxt):
+        wrs = db_api.watch_rule_get_all_by_stack(cnxt,
+                                                 stack_id)
+        if len(wrs) > 0:
+            self._timer_in_thread(stack_id, self._periodic_watcher_task,
+                                  sid=stack_id)
 
     def start(self):
         super(EngineService, self).start()
@@ -111,7 +114,7 @@ class EngineService(service.Service):
         admin_context = context.get_admin_context()
         stacks = db_api.stack_get_all(admin_context)
         for s in stacks:
-            self._start_watch_task(s.id)
+            self._start_watch_task(s.id, admin_context)
 
     @request_context
     def identify_stack(self, cnxt, stack_name):
@@ -218,7 +221,7 @@ class EngineService(service.Service):
             stack.create()
             if stack.action == stack.CREATE and stack.status == stack.COMPLETE:
                 # Schedule a periodic watcher task for this stack
-                self._start_watch_task(stack.id)
+                self._start_watch_task(stack.id, cnxt)
             else:
                 logger.warning("Stack create failed, status %s" % stack.status)
 
index 2ddf4b3809a252fe84a3007dbf2dff0f6b96b2c9..edeae31615fbbaeee8407c5ef33af08ff8faa1a4 100644 (file)
@@ -1136,9 +1136,8 @@ class StackServiceTest(HeatTestCase):
     @stack_context('periodic_watch_task_not_created')
     def test_periodic_watch_task_not_created(self):
         self.eng.stg[self.stack.id] = DummyThreadGroup()
-        self.eng._start_watch_task(self.stack.id)
-        self.assertEqual([self.eng._periodic_watcher_task],
-                         self.eng.stg[self.stack.id].threads)
+        self.eng._start_watch_task(self.stack.id, self.ctx)
+        self.assertEqual([], self.eng.stg[self.stack.id].threads)
 
     def test_periodic_watch_task_created(self):
         stack = get_alarm_stack('period_watch_task_created',
@@ -1148,7 +1147,7 @@ class StackServiceTest(HeatTestCase):
         stack.store()
         stack.create()
         self.eng.stg[stack.id] = DummyThreadGroup()
-        self.eng._start_watch_task(stack.id)
+        self.eng._start_watch_task(stack.id, self.ctx)
         self.assertEqual([self.eng._periodic_watcher_task],
                          self.eng.stg[stack.id].threads)
         self.stack.delete()