Skip to content

Commit

Permalink
Merge pull request #26 from mokshaproject/feature/fix-exception-counting
Browse files Browse the repository at this point in the history
Fix exception counting.
  • Loading branch information
lmacken committed May 8, 2015
2 parents 553cbfb + 85455d5 commit 8cc1aea
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions moksha.hub/moksha/hub/api/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __json__(self):
}
# Reset these counters before returning.
self.headcount_out = self.headcount_in = 0
self._exception_count = 0
return results

def debug(self, message):
Expand Down Expand Up @@ -150,15 +151,8 @@ def _consume_json(self, message):
# Weird. I have no idea...
pass

try:
message_as_dict = {'body': body, 'topic': topic}
self._consume(message_as_dict)
self._exception_count = 0 # Reset if everything went swimmingly
except Exception:
# Otherwise, keep track of how many exceptions we've hit in a row
self._exception_count += 1
# And then re-raise the exception to be logged
raise
message_as_dict = {'body': body, 'topic': topic}
self._consume(message_as_dict)

def _consume(self, message):
self.headcount_in += 1
Expand Down Expand Up @@ -190,6 +184,8 @@ def _work(self):
self.consume(message)
except Exception as e:
self.log.exception(message)
# Keep track of how many exceptions we've hit in a row
self._exception_count += 1

try:
self.post_consume(message)
Expand Down

0 comments on commit 8cc1aea

Please sign in to comment.