From: tierno Date: Mon, 10 Aug 2020 13:53:57 +0000 (+0000) Subject: fix 1187 create notification task with the proper loop X-Git-Tag: v8.0.1rc1~5 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=0d9d4a863e1097021c9effba0a8a85ad17a33f8a;p=osm%2FNBI.git fix 1187 create notification task with the proper loop Also call notifications when there are subscribers Change-Id: Icf6b4f88aaf633282c2736de85803f845b17d4c6 Signed-off-by: tierno --- diff --git a/osm_nbi/notifications.py b/osm_nbi/notifications.py index 9156c2c..2e7ba94 100644 --- a/osm_nbi/notifications.py +++ b/osm_nbi/notifications.py @@ -133,11 +133,13 @@ class NotificationBase: .format(subscriber["subscriptionId"], subscriber["authentication"]["authType"])) - tasks = [] - async with aiohttp.ClientSession(loop=loop) as session: - for notification in notifications: - tasks.append(asyncio.ensure_future(self.send_notification(session, notification, loop=loop), loop=loop)) - await asyncio.gather(*tasks, loop=loop) + if notifications: + tasks = [] + async with aiohttp.ClientSession(loop=loop) as session: + for notification in notifications: + tasks.append(asyncio.ensure_future(self.send_notification(session, notification, loop=loop), + loop=loop)) + await asyncio.gather(*tasks, loop=loop) async def send_notification(self, session: aiohttp.ClientSession, notification: dict, loop: asyncio.AbstractEventLoop = None, retry_count: int = 5, timeout: float = 5.0): diff --git a/osm_nbi/subscriptions.py b/osm_nbi/subscriptions.py index c6105ee..ec70d0c 100644 --- a/osm_nbi/subscriptions.py +++ b/osm_nbi/subscriptions.py @@ -201,7 +201,9 @@ class SubscriptionThread(threading.Thread): event_details) # self.logger.debug("subscribers list: ") # self.logger.debug(subscribers) - asyncio.ensure_future(self.nslcm.send_notifications(subscribers, loop=self.loop)) + if subscribers: + asyncio.ensure_future(self.nslcm.send_notifications(subscribers, loop=self.loop), + loop=self.loop) else: self.logger.debug("Message can not be used for notification of nslcm") elif topic == "nsi":