mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-15 20:33:12 -05:00
refactor: webhook events (#1661)
* refactored EventBusService to work outside FastAPI * extended event models * refactored webhooks to run through event bus * added basic webhook test route * changed get_all to page_all * fixed incorrectly implemented Vue variables * fixed broken webhook test * changed factory from staticmethod to classmethod * made query boundary definitions easier to read
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from typing import Protocol
|
||||
|
||||
import apprise
|
||||
import requests
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
|
||||
from mealie.services.event_bus_service.event_types import Event
|
||||
|
||||
@@ -34,3 +36,15 @@ class ApprisePublisher:
|
||||
raise Exception("Apprise URL Add Failed")
|
||||
|
||||
self.apprise.notify(title=event.message.title, body=event.message.body, tag=tags)
|
||||
|
||||
|
||||
class WebhookPublisher:
|
||||
def __init__(self, hard_fail=False) -> None:
|
||||
self.hard_fail = hard_fail
|
||||
|
||||
def publish(self, event: Event, notification_urls: list[str]):
|
||||
event_payload = jsonable_encoder(event)
|
||||
for url in notification_urls:
|
||||
r = requests.post(url, json=event_payload, timeout=15)
|
||||
if self.hard_fail:
|
||||
r.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user