Make distributer.fire work as it did

This commit is contained in:
Erik Johnston 2015-05-12 13:14:48 +01:00
parent 95dedb866f
commit 8022b27fc2
1 changed files with 27 additions and 17 deletions

View File

@ -15,6 +15,12 @@
from twisted.internet import defer from twisted.internet import defer
from synapse.util.logcontext import (
PreserveLoggingContext, preserve_context_over_deferred,
)
from synapse.util import unwrapFirstError
import logging import logging
@ -99,6 +105,7 @@ class Signal(object):
Returns a Deferred that will complete when all the observers have Returns a Deferred that will complete when all the observers have
completed.""" completed."""
def do(observer):
def eb(failure): def eb(failure):
logger.warning( logger.warning(
"%s signal observer %s failed: %r", "%s signal observer %s failed: %r",
@ -108,14 +115,17 @@ class Signal(object):
failure.value, failure.value,
failure.getTracebackObject())) failure.getTracebackObject()))
if not self.suppress_failures: if not self.suppress_failures:
failure.raiseException() return failure
return defer.maybeDeferred(observer, *args, **kwargs).addErrback(eb)
with PreserveLoggingContext():
deferreds = [ deferreds = [
defer.maybeDeferred(observer, *args, **kwargs) do(observer)
for observer in self.observers for observer in self.observers
] ]
d = defer.gatherResults(deferreds, consumeErrors=True) d = defer.gatherResults(deferreds, consumeErrors=True)
d.addErrback(eb)
return d d.addErrback(unwrapFirstError)
return preserve_context_over_deferred(d)