Skip to content

Commit

Permalink
feat: startup notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dartt0n committed Jul 23, 2024
1 parent 91c7a3d commit 6b88371
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ jobs:
file: ./dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ github.event.release.tag_name }}
3 changes: 3 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ WORKDIR /app
RUN --mount=type=cache,target=/root/.cache \
poetry install --without=dev

ARG APP_VERSION
ENV APP_VERSION=$APP_VERSION

ENV STRAWBERRY_DISABLE_RICH_ERRORS=1
CMD ["poetry", "run", "gunicorn", "main:app", "--bind", "0.0.0.0:8080", "--worker-class", "aiohttp.GunicornWebWorker"]
35 changes: 35 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

import aiohttp
import rich
from dotenv import load_dotenv

Expand All @@ -15,6 +16,38 @@
from src.service.preference import PreferenceService
from src.service.room import RoomService
from src.service.user import UserService
from src.utils.logger.logger import Logger

log = Logger("main")


async def notify_start():
version = os.getenv("APP_VERSION", "dev")
if version == "dev":
return

token = os.getenv("STATUS_TELEGRAM_BOT_TOKEN")
if token is None:
return

chat = os.getenv("STATUS_CHAT_ID")
if chat is None:
return

url = f"https://api.telegram.org/bot{token}/sendMessage"

try:
async with aiohttp.ClientSession() as session:
async with session.post(
url,
data={
"chat_id": chat,
"text": f"🚀 API version <{version}> is online!",
},
) as resp:
resp.raise_for_status()
except Exception as e:
log.error("failed to notify about start: {}", e)


async def app():
Expand Down Expand Up @@ -87,6 +120,8 @@ async def app():

oauth_adapter = TelegramOauthAdapter(telegram_token, jwt_secret, user_service)

await notify_start()

return build_server(
telegram_token=telegram_token,
telegram_secret=telegram_secret,
Expand Down

0 comments on commit 6b88371

Please sign in to comment.