Ping Echo Availability Tactic - SENG-350-2024-fall/Team-1 GitHub Wiki
Source: app/backend/app.py, Lines 113-126.
def heartbeat():
while True:
url = "http://localhost:3000" # URL of React app
try:
response = requests.get(url)
if response.status_code == 200:
logger.info(f"Ping to {url} successful: Front end up")
else:
logger.error(f"Ping to {url} failed with status code {response.status_code}. Front end likely down.")
except requests.ConnectionError:
logger.error(f"Ping to {url} failed due to connection error. Front end likely down.")
time.sleep(5) # Sleep for 5 seconds before the next ping
The Ping/Echo Architecture Tactic for Availability is effectively implemented in this code through the heartbeat
function, which repeatedly sends HTTP GET requests (pings) to the frontend server at http://localhost:3000
every 5 seconds. This function logs the response status, confirming whether the frontend is up (successful response) or down (error or failed connection).
This tactic is a good choice for ensuring system availability, as it provides real-time monitoring of the frontend’s status. By continuously checking the frontend's connectivity, the backend can quickly detect outages, which is crucial in a medical triage system where uninterrupted access is vital. The Ping/Echo tactic also supports proactive maintenance, enabling administrators to address connectivity issues promptly, thereby enhancing system reliability and user trust.