|
|
@ -49,18 +49,18 @@ class Daemon(util.LoggedClass): |
|
|
|
Handles temporary connection issues. Daemon reponse errors |
|
|
|
are raise through DaemonError. |
|
|
|
''' |
|
|
|
prior_msg = None |
|
|
|
skip_count = None |
|
|
|
self.prior_msg = None |
|
|
|
self.skip_count = None |
|
|
|
|
|
|
|
def log_error(msg, skip_once=False): |
|
|
|
if skip_once and skip_count is None: |
|
|
|
skip_count = 1 |
|
|
|
if msg != prior_msg or skip_count == 0: |
|
|
|
skip_count = 10 |
|
|
|
prior_msg = msg |
|
|
|
self.logger.error('{}. Retrying between sleeps...' |
|
|
|
if skip_once and self.skip_count is None: |
|
|
|
self.skip_count = 1 |
|
|
|
if msg != self.prior_msg or self.skip_count == 0: |
|
|
|
self.skip_count = 10 |
|
|
|
self.prior_msg = msg |
|
|
|
self.logger.error('{} Retrying between sleeps...' |
|
|
|
.format(msg)) |
|
|
|
skip_count -= 1 |
|
|
|
self.skip_count -= 1 |
|
|
|
|
|
|
|
data = json.dumps(payload) |
|
|
|
secs = 1 |
|
|
@ -69,23 +69,23 @@ class Daemon(util.LoggedClass): |
|
|
|
async with self.workqueue_semaphore: |
|
|
|
async with aiohttp.post(self.url, data=data) as resp: |
|
|
|
result = processor(await resp.json()) |
|
|
|
if prior_msg: |
|
|
|
if self.prior_msg: |
|
|
|
self.logger.info('connection restored') |
|
|
|
return result |
|
|
|
except asyncio.TimeoutError: |
|
|
|
log_error('timeout error', skip_once=True) |
|
|
|
log_error('timeout error.', skip_once=True) |
|
|
|
except aiohttp.ClientHttpProcessingError: |
|
|
|
log_error('HTTP error', skip_once=True) |
|
|
|
log_error('HTTP error.', skip_once=True) |
|
|
|
except aiohttp.ServerDisconnectedError: |
|
|
|
log_error('disconnected', skip_once=True) |
|
|
|
log_error('disconnected.', skip_once=True) |
|
|
|
except aiohttp.ClientConnectionError: |
|
|
|
log_error('connection problem - is your daemon running?') |
|
|
|
except self.DaemonWarmingUpError: |
|
|
|
log_error('still starting up checking blocks...') |
|
|
|
log_error('still starting up checking blocks.') |
|
|
|
except (asyncio.CancelledError, DaemonError): |
|
|
|
raise |
|
|
|
except Exception as e: |
|
|
|
log_error('request gave unexpected error: {}'.format(e)) |
|
|
|
log_error('request gave unexpected error: {}.'.format(e)) |
|
|
|
await asyncio.sleep(secs) |
|
|
|
secs = min(16, secs * 2) |
|
|
|
|
|
|
|