Add necessary logging contexts

This commit is contained in:
Erik Johnston 2016-04-14 11:33:50 +01:00
parent 96bcfb29c7
commit 56da835eaf
1 changed files with 25 additions and 24 deletions

View File

@ -21,6 +21,7 @@ import logging
import push_rule_evaluator import push_rule_evaluator
import push_tools import push_tools
from synapse.util.logcontext import LoggingContext
from synapse.util.metrics import Measure from synapse.util.metrics import Measure
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -85,9 +86,8 @@ class HttpPusher(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def on_new_notifications(self, min_stream_ordering, max_stream_ordering): def on_new_notifications(self, min_stream_ordering, max_stream_ordering):
with Measure(self.clock, "push.on_new_notifications"): self.max_stream_ordering = max(max_stream_ordering, self.max_stream_ordering)
self.max_stream_ordering = max(max_stream_ordering, self.max_stream_ordering) yield self._process()
yield self._process()
@defer.inlineCallbacks @defer.inlineCallbacks
def on_new_receipts(self, min_stream_id, max_stream_id): def on_new_receipts(self, min_stream_id, max_stream_id):
@ -95,16 +95,16 @@ class HttpPusher(object):
# We could check the receipts are actually m.read receipts here, # We could check the receipts are actually m.read receipts here,
# but currently that's the only type of receipt anyway... # but currently that's the only type of receipt anyway...
with Measure(self.clock, "push.on_new_receipts"): with LoggingContext("push._process"):
badge = yield push_tools.get_badge_count( with Measure(self.clock, "push.on_new_receipts"):
self.hs.get_datastore(), self.user_id badge = yield push_tools.get_badge_count(
) self.hs.get_datastore(), self.user_id
)
yield self.send_badge(badge) yield self.send_badge(badge)
@defer.inlineCallbacks @defer.inlineCallbacks
def on_timer(self): def on_timer(self):
with Measure(self.clock, "push.on_timer"): yield self._process()
yield self._process()
def on_stop(self): def on_stop(self):
if self.timed_call: if self.timed_call:
@ -115,21 +115,22 @@ class HttpPusher(object):
if self.processing: if self.processing:
return return
with Measure(self.clock, "push._process"): with LoggingContext("push._process"):
try: with Measure(self.clock, "push._process"):
self.processing = True try:
# if the max ordering changes while we're running _unsafe_process, self.processing = True
# call it again, and so on until we've caught up. # if the max ordering changes while we're running _unsafe_process,
while True: # call it again, and so on until we've caught up.
starting_max_ordering = self.max_stream_ordering while True:
try: starting_max_ordering = self.max_stream_ordering
yield self._unsafe_process() try:
except: yield self._unsafe_process()
logger.exception("Exception processing notifs") except:
if self.max_stream_ordering == starting_max_ordering: logger.exception("Exception processing notifs")
break if self.max_stream_ordering == starting_max_ordering:
finally: break
self.processing = False finally:
self.processing = False
@defer.inlineCallbacks @defer.inlineCallbacks
def _unsafe_process(self): def _unsafe_process(self):