Skip to content

Commit

Permalink
feat(health): enhance health endpoint to check both API and vlr.gg st…
Browse files Browse the repository at this point in the history
…atus

docs(README): update health endpoint description and response example to reflect new functionality
  • Loading branch information
axsddlr committed Sep 16, 2024
1 parent 093839d commit 4c9197c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,24 @@ All endpoints are relative to [https://vlrggapi.vercel.app](https://vlrggapi.ver
### `/health`

- Method: `GET`
- Description: Returns the health status of the API.
- Response: `Healthy: OK`
- Description: Returns the health status of the API and vlr.gg website.
- Example: `GET https://vlrggapi.vercel.app/health`
- Response Example:

```json
{
"https://vlrggapi.vercel.app": {
"status": "Healthy",
"status_code": 200
},
"https://vlr.gg": {
"status": "Healthy",
"status_code": 200
}
}
```

The response includes the status ("Healthy" or "Unhealthy") and the HTTP status code for both the API and the vlr.gg website. If a site is unreachable, the status will be "Unhealthy" and the status_code will be null.

## Installation

Expand Down
15 changes: 15 additions & 0 deletions api/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ def vlr_live_score():
raise Exception("API response: {}".format(status))
return data

@staticmethod
def check_health():
sites = ["https://vlrggapi.vercel.app", "https://vlr.gg"]
results = {}
for site in sites:
try:
response = requests.get(site, timeout=5)
results[site] = {
"status": "Healthy" if response.status_code == 200 else "Unhealthy",
"status_code": response.status_code,
}
except requests.RequestException:
results[site] = {"status": "Unhealthy", "status_code": None}
return results


if __name__ == "__main__":
print(Vlr.vlr_live_score(self=Vlr()))
2 changes: 1 addition & 1 deletion routers/vlr_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ async def VLR_match(request: Request, q: str):

@router.get("/health")
def health():
return "Healthy: OK"
return vlr.check_health()

0 comments on commit 4c9197c

Please sign in to comment.