Skip to content

Commit

Permalink
Corrected try except if seed node is unavailable (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-rooftop authored Sep 21, 2020
1 parent 98b7eb5 commit c47de85
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bot/handlers/network_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict

from helpers import *
from messages import NETWORK_ERROR_MSG
from messages import *


def show_network_menu(update, context):
Expand Down Expand Up @@ -105,7 +105,7 @@ async def show_vault_key_addresses(update, context):
except Exception as e:
logger.exception(e)
try_message_with_home_menu(context=context, chat_id=update.effective_chat.id,
text="Can't get node addresses, please try again.")
text=NODE_LIST_UNAVAILABLE_ERROR_MSG)
return

monitored_node_accounts = list(filter(lambda x: x['status'] == 'active', node_accounts))
Expand Down
7 changes: 3 additions & 4 deletions bot/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from service.local_storage_service import LocalStorageService
from service.thorchain_network_service import *
from packaging import version
from messages import *


def thornode_checks(context):
Expand Down Expand Up @@ -266,8 +267,7 @@ def check_versions_status(context):
node_accounts = get_node_accounts()
except Exception as e:
logger.exception(e)
message = 'I couldn\'t check the versions of other nodes in network! List of nodes currently unavailable!'
try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=message)
try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=NODE_LIST_UNAVAILABLE_ERROR_MSG)
return

highest_version = max(map(lambda n: n['version'], node_accounts), key=lambda v: version.parse(v))
Expand Down Expand Up @@ -295,8 +295,7 @@ def check_churning(context):
validators = get_node_accounts()
except Exception as e:
logger.exception(e)
message = 'I couldn\'t check the statuses of other nodes in network! List of nodes currently unavailable!'
try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=message)
try_message_with_home_menu(context, chat_id=context.job.context['chat_id'], text=NODE_LIST_UNAVAILABLE_ERROR_MSG)
return


Expand Down
3 changes: 2 additions & 1 deletion bot/messages.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NETWORK_ERROR_MSG = '😱 There was an error while getting data 😱\n Please check your internet connection and try again!'
NETWORK_ERROR_MSG = '😱 There was an error while getting data 😱\nEither your internet connection or the node endpoint is down!'
NODE_LIST_UNAVAILABLE_ERROR_MSG = '😱 I couldn\'t check the versions of other nodes in network! 😱\nList of nodes currently unavailable!'
8 changes: 6 additions & 2 deletions bot/service/thorchain_network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import aiohttp
import requests

from constants import DEBUG, logger, BINANCE_NODE_IP, NETWORK_TYPE, CONNECTION_TIMEOUT
from constants import *


def get_node_accounts():
Expand Down Expand Up @@ -78,7 +78,11 @@ def get_random_seed_node_endpoint() -> str:
random.shuffle(available_node_ips)
response = None
for node_ip in available_node_ips:
response = requests.get(url='http://' + node_ip + ':8080/v1/health', timeout=10)
try:
response = requests.get(url='http://' + node_ip + ':8080/v1/health', timeout=10)
except Exception as e:
logger.exception(e)
continue
if response.status_code == 200:
return node_ip
raise BadStatusException(response)
Expand Down

0 comments on commit c47de85

Please sign in to comment.