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:
Michael Genson
2022-09-27 21:55:20 -05:00
committed by GitHub
parent 025f1bc603
commit 796e55b7d5
11 changed files with 175 additions and 54 deletions

View File

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