Add webhook after update

This commit is contained in:
2021-12-11 18:18:41 +03:00
parent 4588d8e4c3
commit 64992c9c2a
4 changed files with 35 additions and 1 deletions

View File

@@ -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

View 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)

View File

@@ -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()