Run black on per_destination_queue

... mostly to fix pep8 fails
This commit is contained in:
Richard van der Hoff 2019-05-09 16:27:02 +01:00
parent 11ea16777f
commit 130f932cbc

View File

@ -40,8 +40,7 @@ logger = logging.getLogger(__name__)
sent_edus_counter = Counter( sent_edus_counter = Counter(
"synapse_federation_client_sent_edus", "synapse_federation_client_sent_edus", "Total number of EDUs successfully sent"
"Total number of EDUs successfully sent",
) )
sent_edus_by_type = Counter( sent_edus_by_type = Counter(
@ -61,6 +60,7 @@ class PerDestinationQueue(object):
destination (str): the server_name of the destination that we are managing destination (str): the server_name of the destination that we are managing
transmission for. transmission for.
""" """
def __init__(self, hs, transaction_manager, destination): def __init__(self, hs, transaction_manager, destination):
self._server_name = hs.hostname self._server_name = hs.hostname
self._clock = hs.get_clock() self._clock = hs.get_clock()
@ -123,9 +123,7 @@ class PerDestinationQueue(object):
Args: Args:
states (iterable[UserPresenceState]): presence to send states (iterable[UserPresenceState]): presence to send
""" """
self._pending_presence.update({ self._pending_presence.update({state.user_id: state for state in states})
state.user_id: state for state in states
})
self.attempt_new_transaction() self.attempt_new_transaction()
def queue_read_receipt(self, receipt): def queue_read_receipt(self, receipt):
@ -135,14 +133,9 @@ class PerDestinationQueue(object):
Args: Args:
receipt (synapse.api.receipt_info.ReceiptInfo): receipt to be queued receipt (synapse.api.receipt_info.ReceiptInfo): receipt to be queued
""" """
self._pending_rrs.setdefault( self._pending_rrs.setdefault(receipt.room_id, {}).setdefault(
receipt.room_id, {},
).setdefault(
receipt.receipt_type, {} receipt.receipt_type, {}
)[receipt.user_id] = { )[receipt.user_id] = {"event_ids": receipt.event_ids, "data": receipt.data}
"event_ids": receipt.event_ids,
"data": receipt.data,
}
def flush_read_receipts_for_room(self, room_id): def flush_read_receipts_for_room(self, room_id):
# if we don't have any read-receipts for this room, it may be that we've already # if we don't have any read-receipts for this room, it may be that we've already
@ -173,10 +166,7 @@ class PerDestinationQueue(object):
# request at which point pending_pdus just keeps growing. # request at which point pending_pdus just keeps growing.
# we need application-layer timeouts of some flavour of these # we need application-layer timeouts of some flavour of these
# requests # requests
logger.debug( logger.debug("TX [%s] Transaction already in progress", self._destination)
"TX [%s] Transaction already in progress",
self._destination
)
return return
logger.debug("TX [%s] Starting transaction loop", self._destination) logger.debug("TX [%s] Starting transaction loop", self._destination)
@ -243,14 +233,22 @@ class PerDestinationQueue(object):
) )
pending_edus.extend(device_message_edus) pending_edus.extend(device_message_edus)
pending_edus.extend(self._pop_pending_edus(MAX_EDUS_PER_TRANSACTION - len(pending_edus))) pending_edus.extend(
while len(pending_edus) < MAX_EDUS_PER_TRANSACTION and self._pending_edus_keyed: self._pop_pending_edus(MAX_EDUS_PER_TRANSACTION - len(pending_edus))
)
while (
len(pending_edus) < MAX_EDUS_PER_TRANSACTION
and self._pending_edus_keyed
):
_, val = self._pending_edus_keyed.popitem() _, val = self._pending_edus_keyed.popitem()
pending_edus.append(val) pending_edus.append(val)
if pending_pdus: if pending_pdus:
logger.debug("TX [%s] len(pending_pdus_by_dest[dest]) = %d", logger.debug(
self._destination, len(pending_pdus)) "TX [%s] len(pending_pdus_by_dest[dest]) = %d",
self._destination,
len(pending_pdus),
)
if not pending_pdus and not pending_edus: if not pending_pdus and not pending_edus:
logger.debug("TX [%s] Nothing to send", self._destination) logger.debug("TX [%s] Nothing to send", self._destination)
@ -303,22 +301,25 @@ class PerDestinationQueue(object):
except HttpResponseException as e: except HttpResponseException as e:
logger.warning( logger.warning(
"TX [%s] Received %d response to transaction: %s", "TX [%s] Received %d response to transaction: %s",
self._destination, e.code, e, self._destination,
e.code,
e,
) )
except RequestSendFailed as e: except RequestSendFailed as e:
logger.warning("TX [%s] Failed to send transaction: %s", self._destination, e) logger.warning(
"TX [%s] Failed to send transaction: %s", self._destination, e
)
for p, _ in pending_pdus: for p, _ in pending_pdus:
logger.info("Failed to send event %s to %s", p.event_id, logger.info(
self._destination) "Failed to send event %s to %s", p.event_id, self._destination
except Exception:
logger.exception(
"TX [%s] Failed to send transaction",
self._destination,
) )
except Exception:
logger.exception("TX [%s] Failed to send transaction", self._destination)
for p, _ in pending_pdus: for p, _ in pending_pdus:
logger.info("Failed to send event %s to %s", p.event_id, logger.info(
self._destination) "Failed to send event %s to %s", p.event_id, self._destination
)
finally: finally:
# We want to be *very* sure we clear this after we stop processing # We want to be *very* sure we clear this after we stop processing
self.transmission_loop_running = False self.transmission_loop_running = False
@ -367,7 +368,10 @@ class PerDestinationQueue(object):
last_device_stream_id = self._last_device_stream_id last_device_stream_id = self._last_device_stream_id
to_device_stream_id = self._store.get_to_device_stream_token() to_device_stream_id = self._store.get_to_device_stream_token()
contents, stream_id = yield self._store.get_new_device_msgs_for_remote( contents, stream_id = yield self._store.get_new_device_msgs_for_remote(
self._destination, last_device_stream_id, to_device_stream_id, limit - len(edus) self._destination,
last_device_stream_id,
to_device_stream_id,
limit - len(edus),
) )
edus.extend( edus.extend(
Edu( Edu(