mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
watchtower: use network job, catch exceptions
This commit is contained in:
parent
bdb54ef8ca
commit
0c52c1cc8d
1 changed files with 8 additions and 3 deletions
|
@ -47,7 +47,7 @@ class LNWatcher(PrintError):
|
||||||
watchtower_url = self.config.get('watchtower_url')
|
watchtower_url = self.config.get('watchtower_url')
|
||||||
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
|
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
|
||||||
self.watchtower_queue = asyncio.Queue()
|
self.watchtower_queue = asyncio.Queue()
|
||||||
asyncio.run_coroutine_threadsafe(self.watchtower_task(), self.network.asyncio_loop)
|
self.network.start([self.watchtower_task])
|
||||||
|
|
||||||
def with_watchtower(func):
|
def with_watchtower(func):
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
|
@ -56,12 +56,17 @@ class LNWatcher(PrintError):
|
||||||
return func(self, *args, **kwargs)
|
return func(self, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
@aiosafe
|
||||||
async def watchtower_task(self):
|
async def watchtower_task(self):
|
||||||
while True:
|
while True:
|
||||||
name, args, kwargs = await self.watchtower_queue.get()
|
name, args, kwargs = await self.watchtower_queue.get()
|
||||||
self.print_error('sending to watchtower', name, args)
|
|
||||||
func = getattr(self.watchtower, name)
|
func = getattr(self.watchtower, name)
|
||||||
func(*args, **kwargs)
|
try:
|
||||||
|
func(*args, **kwargs)
|
||||||
|
except:
|
||||||
|
self.print_error('could not reach watchtower, will retry in 5s', name, args)
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
await self.watchtower_queue.put((name, args, kwargs))
|
||||||
|
|
||||||
def write_to_disk(self):
|
def write_to_disk(self):
|
||||||
# FIXME: json => every update takes linear instead of constant disk write
|
# FIXME: json => every update takes linear instead of constant disk write
|
||||||
|
|
Loading…
Add table
Reference in a new issue