Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health check endpoint, respin git clone commands if fail #13

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ app.log
chain-registry.zip
cosmos-chain-registry*
__pycache__/*
chain-registry/
17 changes: 16 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def get_healthy_rest_endpoints(rest_endpoints):
def is_endpoint_healthy(endpoint):
try:
response = requests.get(f"{endpoint}/health", timeout=1, verify=False)
# some chains dont implement the /health endpoint. Should we just skip /health and go directly to the below?
if response.status_code == 501:
response = requests.get(f"{endpoint}/cosmos/gov/v1beta1/proposals?proposal_status=2", timeout=1, verify=False)
return response.status_code == 200
except:
return False
Expand Down Expand Up @@ -277,13 +280,22 @@ def fetch_data_for_network(network, network_type, repo_path):

rest_endpoints = data.get("apis", {}).get("rest", [])
rpc_endpoints = data.get("apis", {}).get("rpc", [])
print(f"Found {len(rest_endpoints)} rest endpoints and {len(rpc_endpoints)} rpc endpoints for {network}")

# Prioritize RPC endpoints for fetching the latest block height
latest_block_height = -1
healthy_rpc_endpoints = get_healthy_rpc_endpoints(rpc_endpoints)
healthy_rest_endpoints = get_healthy_rest_endpoints(rest_endpoints)

if len(healthy_rpc_endpoints) == 0:
print(f"No healthy RPC endpoints found for network {network}. Skipping...")
return None

if len(healthy_rest_endpoints) == 0:
print(f"No healthy REST endpoints found for network {network}. Skipping...")
return None

print(f"Found {len(healthy_rest_endpoints)} rest endpoints and {len(healthy_rpc_endpoints)} rpc endpoints for {network}")

# Shuffle the healthy endpoints
shuffle(healthy_rpc_endpoints)
shuffle(healthy_rest_endpoints)
Expand Down Expand Up @@ -381,6 +393,9 @@ def update_data():
print(f"Repo path: {repo_path}")
except Exception as e:
print(f"Error downloading and extracting repo: {e}")
print("Error encountered. Sleeping for 5 seconds before retrying...")
sleep(5)
continue

try:
# Process mainnets & testnets
Expand Down
1 change: 0 additions & 1 deletion chain-registry
Submodule chain-registry deleted from 6a30b1
Loading