Heartbeat 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 Heartbeat Architecture Tactic for Availability is effectively used in this code through the heartbeat
function, which continuously pings the frontend server (localhost:3000
) every 5 seconds to check if it is online. This function runs on a separate thread, enabling it to operate independently of the main application logic. Each ping attempt logs whether the frontend is accessible, allowing administrators to detect and respond to downtime promptly.
This approach is a good choice for availability because it ensures continuous monitoring of the system's key components. If the frontend becomes unavailable, the logs provide immediate feedback, aiding in faster diagnosis and resolution of issues. By using the Heartbeat tactic, the system maintains higher resilience and reliability, which are essential in critical applications like medical triage systems.