From c4aad3b3e5fc073b74cc7b963d49975004b5ea17 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Tue, 28 Jul 2015 15:05:49 +0200 Subject: [PATCH] Skip tasks run when there is no subscriber This skips taskflow launch when the notifier is called for a queue without subscriber, preventing a traceback. Change-Id: I63571a163efae523e52798fe4039f48859fa1fee Closes-Bug: #1478841 --- zaqar/notification/notifier.py | 7 ++++--- zaqar/tests/unit/notification/test_notifier.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/zaqar/notification/notifier.py b/zaqar/notification/notifier.py index 9a06af18b..dcb64e2b9 100644 --- a/zaqar/notification/notifier.py +++ b/zaqar/notification/notifier.py @@ -65,8 +65,9 @@ class NotifierDriver(object): for m in messages: wh_flow.add(self._generate_task(s['subscriber'], m)) - e = engines.load(wh_flow, executor=self.executor, - engine='parallel') - e.run() + if wh_flow: + e = engines.load(wh_flow, executor=self.executor, + engine='parallel') + e.run() else: LOG.error('Failed to get subscription controller.') diff --git a/zaqar/tests/unit/notification/test_notifier.py b/zaqar/tests/unit/notification/test_notifier.py index 044cb003f..b4aa8b001 100644 --- a/zaqar/tests/unit/notification/test_notifier.py +++ b/zaqar/tests/unit/notification/test_notifier.py @@ -70,3 +70,12 @@ class NotifierTest(testing.TestBase): subscriber = self.subscription[0]['subscriber'] new_task = self.driver._generate_task(subscriber, self.messages) self.assertIsInstance(new_task, task.webhook.WebhookTask) + + def test_post_no_subscriber(self): + ctlr = mock.MagicMock() + ctlr.list = mock.Mock(return_value=iter([[]])) + driver = notifier.NotifierDriver(subscription_controller=ctlr) + with mock.patch('requests.post') as mock_post: + driver.post('fake_queue', self.messages, self.client_id, + self.project) + self.assertEqual(0, mock_post.call_count)