mirror of
https://github.com/flibusta-apps/library_updater.git
synced 2025-12-06 07:45:35 +01:00
Add webhook after update
This commit is contained in:
@@ -4,3 +4,4 @@ asyncpg
|
||||
aiomysql
|
||||
uvicorn[standart]
|
||||
aiologger
|
||||
httpx
|
||||
|
||||
@@ -8,6 +8,7 @@ from aiologger import Logger
|
||||
|
||||
from core.config import env_config
|
||||
from app.services.updaters.base import BaseUpdater
|
||||
from app.services.webhook import WebhookSender
|
||||
|
||||
|
||||
async def run(cmd) -> tuple[bytes, bytes, Optional[int]]:
|
||||
@@ -474,6 +475,8 @@ class FlUpdater(BaseUpdater):
|
||||
self._update_books_genres()
|
||||
)
|
||||
|
||||
await WebhookSender.send()
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
|
||||
21
src/app/services/webhook.py
Normal file
21
src/app/services/webhook.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import httpx
|
||||
|
||||
from core.config import env_config, WebhookConfig
|
||||
|
||||
|
||||
class WebhookSender:
|
||||
@classmethod
|
||||
async def _make_request(cls, webhook: WebhookConfig):
|
||||
async with httpx.AsyncClient() as client:
|
||||
request_maker= getattr(client, webhook.method)
|
||||
await request_maker(webhook.url, headers=webhook.headers)
|
||||
|
||||
@classmethod
|
||||
async def send(cls):
|
||||
webhooks = env_config.WEBHOOKS
|
||||
|
||||
if webhooks is None:
|
||||
return
|
||||
|
||||
for webhook in webhooks:
|
||||
await cls._make_request(webhook)
|
||||
@@ -1,4 +1,11 @@
|
||||
from pydantic import BaseSettings
|
||||
from typing import Optional, Union, Literal
|
||||
from pydantic import BaseModel, BaseSettings
|
||||
|
||||
|
||||
class WebhookConfig(BaseModel):
|
||||
method: Union[Literal['get'], Literal['post']]
|
||||
url: str
|
||||
headers: dict[str, str]
|
||||
|
||||
|
||||
class EnvConfig(BaseSettings):
|
||||
@@ -18,5 +25,7 @@ class EnvConfig(BaseSettings):
|
||||
|
||||
FL_BASE_URL: str
|
||||
|
||||
WEBHOOKS: Optional[list[WebhookConfig]]
|
||||
|
||||
|
||||
env_config = EnvConfig()
|
||||
|
||||
Reference in New Issue
Block a user