Skip to content

Commit

Permalink
Ruff
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Schultz <[email protected]>
  • Loading branch information
dylanschultzie committed Jul 5, 2024
1 parent 0a4850c commit 265176b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/cosmos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
from datetime import datetime, timedelta, timezone


def cosmos_health(ip: str, port: str, acceptable_time_delta: int = 60) -> tuple:
acceptable_time_delta = timedelta(seconds=acceptable_time_delta)

Expand All @@ -18,7 +19,7 @@ def cosmos_health(ip: str, port: str, acceptable_time_delta: int = 60) -> tuple:

current_dt = datetime.now(timezone.utc)
latest_block_time = latest_block_data["result"]["sync_info"]["latest_block_time"]
truncated_time_str = latest_block_time[:-4] + 'Z'
truncated_time_str = latest_block_time[:-4] + "Z"
latest_block_dt = datetime.strptime(truncated_time_str, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
block_time_delta = current_dt - latest_block_dt

Expand Down
3 changes: 2 additions & 1 deletion app/ethereum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import datetime, timedelta, timezone
import requests


def ethereum_health(ip: str, port: str, acceptable_time_delta: int = 60):
acceptable_time_delta = timedelta(seconds=acceptable_time_delta)

# Get latest block data
payload = {
"jsonrpc": "2.0",
Expand Down
7 changes: 5 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from dotenv import load_dotenv
from flask import Flask, request
from app.ethereum import ethereum_health
Expand All @@ -12,25 +10,30 @@
# Time in seconds between current time and last block
ACCEPTABLE_DELTA = 60


@app.route("/ethereum", methods=["GET"])
def ethereum_health_check():
ip, port = parse_request(request)
message, status = ethereum_health(ip, port)
return message, status


@app.route("/cosmos", methods=["GET"])
def health_check():
ip, port = parse_request(request)
message, status = cosmos_health(ip, port)
return message, status


def parse_request(req) -> tuple:
port = req.headers.get("Port")
host = req.headers.get("Host")
ip_address = host.split(":")[0]
return ip_address, port


def main():
app.run(host="0.0.0.0", port=53336)


main()

0 comments on commit 265176b

Please sign in to comment.