squidge to 79 columns as per pep8

This commit is contained in:
Matthew Hodgson 2014-12-10 00:03:55 +00:00
parent 8ada2d2018
commit 2b1acb7671
3 changed files with 36 additions and 19 deletions

View File

@ -778,21 +778,25 @@ class _TransactionQueue(object):
def _attempt_new_transaction(self, destination): def _attempt_new_transaction(self, destination):
(retry_last_ts, retry_interval) = (0, 0) (retry_last_ts, retry_interval) = (0, 0)
retry_timings = yield self.store.get_destination_retry_timings(destination) retry_timings = yield self.store.get_destination_retry_timings(
destination
)
if retry_timings: if retry_timings:
(retry_last_ts, retry_interval) = ( (retry_last_ts, retry_interval) = (
retry_timings.retry_last_ts, retry_timings.retry_interval retry_timings.retry_last_ts, retry_timings.retry_interval
) )
if retry_last_ts + retry_interval > int(self._clock.time_msec()): if retry_last_ts + retry_interval > int(self._clock.time_msec()):
logger.info("TX [%s] not ready for retry yet - dropping transaction for now", destination) logger.info("TX [%s] not ready for retry yet - "
"dropping transaction for now", destination)
return return
else: else:
logger.info("TX [%s] is ready for retry", destination) logger.info("TX [%s] is ready for retry", destination)
if destination in self.pending_transactions: if destination in self.pending_transactions:
# XXX: pending_transactions can get stuck on by a never-ending request # XXX: pending_transactions can get stuck on by a never-ending
# at which point pending_pdus_by_dest just keeps growing. # request at which point pending_pdus_by_dest just keeps growing.
# we need application-layer timeouts of some flavour of these requests # we need application-layer timeouts of some flavour of these
# requests
return return
# list of (pending_pdu, deferred, order) # list of (pending_pdu, deferred, order)
@ -803,8 +807,10 @@ class _TransactionQueue(object):
if not pending_pdus and not pending_edus and not pending_failures: if not pending_pdus and not pending_edus and not pending_failures:
return return
logger.debug("TX [%s] Attempting new transaction (pdus: %d, edus: %d, failures: %d)", logger.debug("TX [%s] Attempting new transaction "
destination, len(pending_pdus), len(pending_edus), len(pending_failures)) "(pdus: %d, edus: %d, failures: %d)",
destination,
len(pending_pdus), len(pending_edus), len(pending_failures))
# Sort based on the order field # Sort based on the order field
pending_pdus.sort(key=lambda t: t[2]) pending_pdus.sort(key=lambda t: t[2])
@ -837,7 +843,8 @@ class _TransactionQueue(object):
yield self.transaction_actions.prepare_to_send(transaction) yield self.transaction_actions.prepare_to_send(transaction)
logger.debug("TX [%s] Persisted transaction", destination) logger.debug("TX [%s] Persisted transaction", destination)
logger.info("TX [%s] Sending transaction [%s]", destination, transaction.transaction_id) logger.info("TX [%s] Sending transaction [%s]", destination,
transaction.transaction_id)
# Actually send the transaction # Actually send the transaction
@ -874,7 +881,9 @@ class _TransactionQueue(object):
if code == 200: if code == 200:
if retry_last_ts: if retry_last_ts:
# this host is alive! reset retry schedule # this host is alive! reset retry schedule
yield self.store.set_destination_retry_timings(destination, 0, 0) yield self.store.set_destination_retry_timings(
destination, 0, 0
)
deferred.callback(None) deferred.callback(None)
else: else:
self.start_retrying(destination, retry_interval) self.start_retrying(destination, retry_interval)
@ -892,7 +901,8 @@ class _TransactionQueue(object):
except Exception as e: except Exception as e:
# We capture this here as there as nothing actually listens # We capture this here as there as nothing actually listens
# for this finishing functions deferred. # for this finishing functions deferred.
logger.exception("TX [%s] Problem in _attempt_transaction: %s", destination, e) logger.exception("TX [%s] Problem in _attempt_transaction: %s",
destination, e)
self.start_retrying(destination, retry_interval) self.start_retrying(destination, retry_interval)

View File

@ -90,7 +90,7 @@ class MatrixFederationHttpClient(object):
) )
logger.info("Sending request to %s: %s %s", logger.info("Sending request to %s: %s %s",
destination, method, url_bytes) destination, method, url_bytes)
logger.debug( logger.debug(
"Types: %s", "Types: %s",
@ -135,7 +135,7 @@ class MatrixFederationHttpClient(object):
raise SynapseError(400, "Domain specified not found.") raise SynapseError(400, "Domain specified not found.")
logger.exception("Sending request failed to %s: %s %s : %s", logger.exception("Sending request failed to %s: %s %s : %s",
destination, method, url_bytes, e) destination, method, url_bytes, e)
_print_ex(e) _print_ex(e)
if retries_left: if retries_left:
@ -145,7 +145,8 @@ class MatrixFederationHttpClient(object):
raise raise
logger.info("Received response %d %s for %s: %s %s", logger.info("Received response %d %s for %s: %s %s",
response.code, response.phrase, destination, method, url_bytes) response.code, response.phrase,
destination, method, url_bytes)
if 200 <= response.code < 300: if 200 <= response.code < 300:
# We need to update the transactions table to say it was sent? # We need to update the transactions table to say it was sent?

View File

@ -28,7 +28,8 @@ class TransactionStore(SQLBaseStore):
"""A collection of queries for handling PDUs. """A collection of queries for handling PDUs.
""" """
# a write-through cache of DestinationsTable.EntryType indexed by destination string # a write-through cache of DestinationsTable.EntryType indexed by
# destination string
destination_retry_cache = {} destination_retry_cache = {}
def get_received_txn_response(self, transaction_id, origin): def get_received_txn_response(self, transaction_id, origin):
@ -238,7 +239,8 @@ class TransactionStore(SQLBaseStore):
else: else:
return None return None
def set_destination_retry_timings(self, destination, retry_last_ts, retry_interval): def set_destination_retry_timings(self, destination,
retry_last_ts, retry_interval):
"""Sets the current retry timings for a given destination. """Sets the current retry timings for a given destination.
Both timings should be zero if retrying is no longer occuring. Both timings should be zero if retrying is no longer occuring.
@ -249,15 +251,19 @@ class TransactionStore(SQLBaseStore):
""" """
self.destination_retry_cache[destination] = ( self.destination_retry_cache[destination] = (
DestinationsTable.EntryType(destination, retry_last_ts, retry_interval) DestinationsTable.EntryType(destination,
retry_last_ts, retry_interval)
) )
# xxx: we could chose to not bother persisting this if our cache things this is a NOOP # XXX: we could chose to not bother persisting this if our cache thinks
# this is a NOOP
return self.runInteraction( return self.runInteraction(
"set_destination_retry_timings", "set_destination_retry_timings",
self._set_destination_retry_timings, destination, retry_last_ts, retry_interval) self._set_destination_retry_timings, destination,
retry_last_ts, retry_interval)
def _set_destination_retry_timings(cls, txn, destination, retry_last_ts, retry_interval): def _set_destination_retry_timings(cls, txn, destination,
retry_last_ts, retry_interval):
query = ( query = (
"INSERT OR REPLACE INTO %s " "INSERT OR REPLACE INTO %s "