-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add timestamp to prices and keep last updated at in publisher * Add .idea/ to .gitignore * add a simple health check api * add port and health check logic * run black * empty * run pre-commit * undo remove blank line * fix: update the last successful update only when it's greater * refactor: fix typings in pyth replicator * fix: type error in coin_gecko.py * refactor: health check code to improve readability and performance * fix: logic error updating last successful update * chore: update version to 1.1.0 in pyproject.toml * refactor: rename port to health_check_port * refactor: rename health_check_test_period_secs to health_check_threshold_secs * refactor: use fastapi for health check api * chore: format imports * Refactor health check API and add is_healthy method to Publisher class --------- Co-authored-by: Keyvan <[email protected]>
- Loading branch information
1 parent
2fbd4b6
commit 6f1802a
Showing
11 changed files
with
671 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,3 +131,6 @@ dmypy.json | |
# Visual Studio Code | ||
.vscode/ | ||
.devcontainer/ | ||
|
||
# PyCharm | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from fastapi import FastAPI, status | ||
from fastapi.responses import JSONResponse | ||
from example_publisher.publisher import Publisher | ||
|
||
|
||
class API(FastAPI): | ||
publisher: Publisher | ||
|
||
|
||
app = API() | ||
|
||
|
||
@app.get("/health") | ||
def health_check(): | ||
healthy = API.publisher.is_healthy() | ||
last_successful_update = API.publisher.last_successful_update | ||
if not healthy: | ||
return JSONResponse( | ||
content={ | ||
"status": "error", | ||
"last_successful_update": last_successful_update, | ||
}, | ||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, | ||
) | ||
return JSONResponse( | ||
content={ | ||
"status": "ok", | ||
"last_successful_update": last_successful_update, | ||
}, | ||
status_code=status.HTTP_200_OK, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.