From b6bfa2adc6b04d7a9895ebb74c985e5c7a3da4b7 Mon Sep 17 00:00:00 2001 From: Ovv Date: Fri, 15 Jun 2018 15:40:47 +0200 Subject: [PATCH 1/2] Shield BaseNotifier from implementation close #10 --- isitdown/notifiers/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/isitdown/notifiers/__init__.py b/isitdown/notifiers/__init__.py index 28ae219..a57a664 100644 --- a/isitdown/notifiers/__init__.py +++ b/isitdown/notifiers/__init__.py @@ -30,7 +30,10 @@ async def error(self, result): self.errors[result.check] += 1 self.states[result.check] = state.ERROR - await self._dispatch_error(result) + try: + await self._dispatch_error(result) + except Exception: + LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) async def ok(self, result): if result.check not in self.errors: @@ -41,9 +44,15 @@ async def ok(self, result): if self.states[result.check] == state.ERROR: self.states[result.check] = state.OK self.errors[result.check] = 0 - await self._recover(result) + try: + await self._recover(result) + except Exception: + LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) else: - await self._ok(result) + try: + await self._ok(result) + except Exception as e: + LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) async def _dispatch_error(self, result): From 7eed1557cd304605281b48993320cd1749d42eb9 Mon Sep 17 00:00:00 2001 From: Ovv Date: Fri, 15 Jun 2018 19:51:48 +0200 Subject: [PATCH 2/2] black --- isitdown/notifiers/__init__.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/isitdown/notifiers/__init__.py b/isitdown/notifiers/__init__.py index a57a664..cab2408 100644 --- a/isitdown/notifiers/__init__.py +++ b/isitdown/notifiers/__init__.py @@ -33,7 +33,11 @@ async def error(self, result): try: await self._dispatch_error(result) except Exception: - LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) + LOG.exception( + "Error while notifying: %s, state: %s", + result.check, + self.states[result.check], + ) async def ok(self, result): if result.check not in self.errors: @@ -47,12 +51,20 @@ async def ok(self, result): try: await self._recover(result) except Exception: - LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) + LOG.exception( + "Error while notifying: %s, state: %s", + result.check, + self.states[result.check], + ) else: try: await self._ok(result) except Exception as e: - LOG.exception('Error while notifying: %s, state: %s', result.check, self.states[result.check]) + LOG.exception( + "Error while notifying: %s, state: %s", + result.check, + self.states[result.check], + ) async def _dispatch_error(self, result):