Make down and last_error_time locals
This commit is contained in:
parent
9ebd2e86e8
commit
6dafbfd455
@ -47,8 +47,6 @@ class Daemon(object):
|
|||||||
# Limit concurrent RPC calls to this number.
|
# Limit concurrent RPC calls to this number.
|
||||||
# See DEFAULT_HTTP_WORKQUEUE in bitcoind, which is typically 16
|
# See DEFAULT_HTTP_WORKQUEUE in bitcoind, which is typically 16
|
||||||
self.workqueue_semaphore = asyncio.Semaphore(value=max_workqueue)
|
self.workqueue_semaphore = asyncio.Semaphore(value=max_workqueue)
|
||||||
self.down = False
|
|
||||||
self.last_error_time = 0
|
|
||||||
self._available_rpcs = {} # caches results for _is_rpc_available()
|
self._available_rpcs = {} # caches results for _is_rpc_available()
|
||||||
|
|
||||||
def set_urls(self, urls):
|
def set_urls(self, urls):
|
||||||
@ -99,17 +97,20 @@ class Daemon(object):
|
|||||||
are raise through DaemonError.
|
are raise through DaemonError.
|
||||||
'''
|
'''
|
||||||
def log_error(error):
|
def log_error(error):
|
||||||
self.down = True
|
nonlocal down, last_error_time
|
||||||
|
down = True
|
||||||
now = time.time()
|
now = time.time()
|
||||||
prior_time = self.last_error_time
|
prior_time = last_error_time
|
||||||
if now - prior_time > 60:
|
if now - prior_time > 60:
|
||||||
self.last_error_time = now
|
last_error_time = now
|
||||||
if prior_time and self.failover():
|
if prior_time and self.failover():
|
||||||
secs = 0
|
secs = 0
|
||||||
else:
|
else:
|
||||||
self.logger.error('{} Retrying occasionally...'
|
self.logger.error('{} Retrying occasionally...'
|
||||||
.format(error))
|
.format(error))
|
||||||
|
|
||||||
|
down = False
|
||||||
|
last_error_time = 0
|
||||||
data = json.dumps(payload)
|
data = json.dumps(payload)
|
||||||
secs = 1
|
secs = 1
|
||||||
max_secs = 4
|
max_secs = 4
|
||||||
@ -118,9 +119,7 @@ class Daemon(object):
|
|||||||
result = await self._send_data(data)
|
result = await self._send_data(data)
|
||||||
if not isinstance(result, tuple):
|
if not isinstance(result, tuple):
|
||||||
result = processor(result)
|
result = processor(result)
|
||||||
if self.down:
|
if down:
|
||||||
self.down = False
|
|
||||||
self.last_error_time = 0
|
|
||||||
self.logger.info('connection restored')
|
self.logger.info('connection restored')
|
||||||
return result
|
return result
|
||||||
log_error('HTTP error code {:d}: {}'
|
log_error('HTTP error code {:d}: {}'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user