-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add healthcheck endpoint (#10)
- Loading branch information
Showing
7 changed files
with
73 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
|
||
# Allow files and directories | ||
!/webhook_telegram_bot | ||
!/healthcheck.py | ||
!/poetry.lock | ||
!/pyproject.toml |
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,27 @@ | ||
#!/usr/bin/env python | ||
"""Custom healthcheck script.""" | ||
import sys | ||
from urllib.error import HTTPError, URLError | ||
from urllib.request import urlopen | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Entrypoint. | ||
:return: None | ||
""" | ||
try: | ||
response = urlopen('http://127.0.0.1:8080/api/v1/health') # nosec | ||
if response.code == 200: | ||
sys.exit(0) | ||
else: | ||
sys.exit(1) | ||
except HTTPError: | ||
sys.exit(1) | ||
except URLError: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,16 @@ | ||
from aiohttp import web | ||
|
||
from webhook_telegram_bot.main import init_routes | ||
|
||
|
||
async def test_health_handler(aiohttp_client): | ||
app = web.Application() | ||
init_routes(app) | ||
client = await aiohttp_client(app) | ||
url = client.app.router["health"].url_for() | ||
result = await client.get(url) | ||
|
||
assert result.status == 200 | ||
|
||
data = await result.json() | ||
assert data.get("health") == "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""This file contains handlers for common purposes.""" | ||
from aiohttp import web | ||
from aiohttp.web_response import Response | ||
|
||
|
||
async def health_handler(request: web.Request) -> Response: | ||
""" | ||
Return healthcheck response. | ||
:return: Response | ||
""" | ||
return web.json_response({"health": "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