Only log when the network first goes down
parent
bb44b9854b
commit
0cccdd01b5
|
@ -49,15 +49,21 @@ async def quote(brokermod: ModuleType, tickers: [str]) -> dict:
|
||||||
async def wait_for_network(get_quotes, sleep=1):
|
async def wait_for_network(get_quotes, sleep=1):
|
||||||
"""Wait until the network comes back up.
|
"""Wait until the network comes back up.
|
||||||
"""
|
"""
|
||||||
|
down = False
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
with trio.move_on_after(1) as cancel_scope:
|
with trio.move_on_after(1) as cancel_scope:
|
||||||
return await get_quotes()
|
quotes = await get_quotes()
|
||||||
|
if down:
|
||||||
|
log.warn("Network is back up")
|
||||||
|
return quotes
|
||||||
if cancel_scope.cancelled_caught:
|
if cancel_scope.cancelled_caught:
|
||||||
log.warn("Quote query timed out")
|
log.warn("Quote query timed out")
|
||||||
continue
|
continue
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
log.warn(f"Network is down waiting for reestablishment...")
|
if not down: # only report/log network down once
|
||||||
|
log.warn(f"Network is down waiting for re-establishment...")
|
||||||
|
down = True
|
||||||
await trio.sleep(sleep)
|
await trio.sleep(sleep)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue