Compare commits
4 commits
master
...
exit_on_di
Author | SHA1 | Date | |
---|---|---|---|
|
8bd7008fdc | ||
|
888bd85470 | ||
|
f2777a7138 | ||
|
b56dbd19f9 |
3 changed files with 26 additions and 3 deletions
|
@ -574,6 +574,9 @@ class TranscodeConfig(BaseConfig):
|
||||||
class CLIConfig(TranscodeConfig):
|
class CLIConfig(TranscodeConfig):
|
||||||
|
|
||||||
api = String('Host name and port for lbrynet daemon API.', 'localhost:5279', metavar='HOST:PORT')
|
api = String('Host name and port for lbrynet daemon API.', 'localhost:5279', metavar='HOST:PORT')
|
||||||
|
exit_on_disconnect = Toggle(
|
||||||
|
'Shutdown daemon when connection to wallet server closes.', False
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api_connection_url(self) -> str:
|
def api_connection_url(self) -> str:
|
||||||
|
|
|
@ -190,7 +190,8 @@ class WalletManager:
|
||||||
'jurisdiction': config.jurisdiction,
|
'jurisdiction': config.jurisdiction,
|
||||||
'concurrent_hub_requests': config.concurrent_hub_requests,
|
'concurrent_hub_requests': config.concurrent_hub_requests,
|
||||||
'data_path': config.wallet_dir,
|
'data_path': config.wallet_dir,
|
||||||
'tx_cache_size': config.transaction_cache_size
|
'tx_cache_size': config.transaction_cache_size,
|
||||||
|
'exit_on_disconnect': config.exit_on_disconnect,
|
||||||
}
|
}
|
||||||
if 'LBRY_FEE_PER_NAME_CHAR' in os.environ:
|
if 'LBRY_FEE_PER_NAME_CHAR' in os.environ:
|
||||||
ledger_config['fee_per_name_char'] = int(os.environ.get('LBRY_FEE_PER_NAME_CHAR'))
|
ledger_config['fee_per_name_char'] = int(os.environ.get('LBRY_FEE_PER_NAME_CHAR'))
|
||||||
|
@ -244,6 +245,7 @@ class WalletManager:
|
||||||
'hub_timeout': self.config.hub_timeout,
|
'hub_timeout': self.config.hub_timeout,
|
||||||
'concurrent_hub_requests': self.config.concurrent_hub_requests,
|
'concurrent_hub_requests': self.config.concurrent_hub_requests,
|
||||||
'data_path': self.config.wallet_dir,
|
'data_path': self.config.wallet_dir,
|
||||||
|
'exit_on_disconnect': self.config.exit_on_disconnect,
|
||||||
}
|
}
|
||||||
if Config.lbryum_servers.is_set(self.config):
|
if Config.lbryum_servers.is_set(self.config):
|
||||||
self.ledger.config['explicit_servers'] = self.config.lbryum_servers
|
self.ledger.config['explicit_servers'] = self.config.lbryum_servers
|
||||||
|
|
|
@ -3,6 +3,7 @@ import asyncio
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import random
|
import random
|
||||||
|
import sys
|
||||||
from time import perf_counter
|
from time import perf_counter
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Optional, Tuple
|
||||||
|
@ -197,6 +198,10 @@ class Network:
|
||||||
def jurisdiction(self):
|
def jurisdiction(self):
|
||||||
return self.config.get("jurisdiction")
|
return self.config.get("jurisdiction")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def exit_on_disconnect(self):
|
||||||
|
return self.config["exit_on_disconnect"]
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
if self._keepalive_task and not self._keepalive_task.done():
|
if self._keepalive_task and not self._keepalive_task.done():
|
||||||
self._keepalive_task.cancel()
|
self._keepalive_task.cancel()
|
||||||
|
@ -373,7 +378,13 @@ class Network:
|
||||||
def rpc(self, list_or_method, args, restricted=True, session: Optional[ClientSession] = None):
|
def rpc(self, list_or_method, args, restricted=True, session: Optional[ClientSession] = None):
|
||||||
if session or self.is_connected:
|
if session or self.is_connected:
|
||||||
session = session or self.client
|
session = session or self.client
|
||||||
return session.send_request(list_or_method, args)
|
try:
|
||||||
|
return session.send_request(list_or_method, args)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
if self.exit_on_disconnect:
|
||||||
|
log.error("exiting on server disconnect")
|
||||||
|
sys.exit(1)
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
self._urgent_need_reconnect.set()
|
self._urgent_need_reconnect.set()
|
||||||
raise ConnectionError("Attempting to send rpc request when connection is not available.")
|
raise ConnectionError("Attempting to send rpc request when connection is not available.")
|
||||||
|
@ -387,9 +398,16 @@ class Network:
|
||||||
try:
|
try:
|
||||||
return await function(*args, **kwargs)
|
return await function(*args, **kwargs)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
log.warning("Wallet server call timed out, retrying.")
|
if self.exit_on_disconnect:
|
||||||
|
log.error("Wallet server call timed out, exiting on server disconnect.")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
log.warning("Wallet server call timed out, retrying.")
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
log.warning("connection error")
|
log.warning("connection error")
|
||||||
|
if self.exit_on_disconnect:
|
||||||
|
log.error("exiting on server disconnect")
|
||||||
|
sys.exit(1)
|
||||||
raise asyncio.CancelledError() # if we got here, we are shutting down
|
raise asyncio.CancelledError() # if we got here, we are shutting down
|
||||||
|
|
||||||
def _update_remote_height(self, header_args):
|
def _update_remote_height(self, header_args):
|
||||||
|
|
Loading…
Add table
Reference in a new issue