Skip to content

Commit

Permalink
Merge pull request #7 from EvoluxBR/before-and-after-handle
Browse files Browse the repository at this point in the history
Add before and after handle
  • Loading branch information
italorossi authored Dec 8, 2016
2 parents ca63b3e + 1195779 commit 9cfe1b3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions greenswitch/esl.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ def handle_event(self, event):
event.parse_data(data)
self._esl_event_queue.put(event)

def _safe_exec_handler(self, handler, event):
try:
handler(event)
except:
logging.exception('ESL %s raised exception.' % handler.__name__)
logging.error(pprint.pformat(event.headers))

def process_events(self):
logging.debug('Event Processor Running')
while self._run:
Expand All @@ -144,14 +151,14 @@ def process_events(self):
if not handlers:
continue

if hasattr(self, 'before_handle'):
self._safe_exec_handler(self.before_handle, event)

for handle in handlers:
try:
handle(event)
except:
logging.exception(
'ESL handler %s raised exception.' %
handle.__name__)
logging.error(pprint.pformat(event.headers))
self._safe_exec_handler(handle, event)

if hasattr(self, 'after_handle'):
self._safe_exec_handler(self.after_handle, event)

def send(self, data):
if not self.connected:
Expand Down

0 comments on commit 9cfe1b3

Please sign in to comment.