refactor: event bus refactor (#1574)

* refactored event dispatching
added EventDocumentType and EventOperation to Event
added event listeners to bulk recipe changes
overhauled shopping list item events to be more useful
modified shopping list item repo to return more information

* added internal documentation for event types

* renamed message_types.py to event_types.py

* added unique event id and fixed instantiation

* generalized event listeners and publishers
moved apprise publisher to new apprise event listener
fixed duplicate message bug with apprise publisher

* added JWT field for user-specified integration id

* removed obselete test notification route

* tuned up existing notification tests

* added dependency to get integration_id from jwt

* added base crud controller to facilitate events

* simplified event publishing

* temporarily fixed test notification
This commit is contained in:
Michael Genson
2022-08-27 13:52:45 -05:00
committed by GitHub
parent caa9e03050
commit 23c039b42d
17 changed files with 720 additions and 403 deletions

View File

@@ -2,11 +2,11 @@ from typing import Protocol
import apprise
from mealie.services.event_bus_service.event_bus_service import EventBusMessage
from mealie.services.event_bus_service.event_types import Event
class PublisherLike(Protocol):
def publish(self, event: EventBusMessage, notification_urls: list[str]):
def publish(self, event: Event, notification_urls: list[str]):
...
@@ -19,11 +19,18 @@ class ApprisePublisher:
self.apprise = apprise.Apprise(asset=asset)
self.hard_fail = hard_fail
def publish(self, event: EventBusMessage, notification_urls: list[str]):
def publish(self, event: Event, notification_urls: list[str]):
"""Publishses a list of notification URLs"""
tags = []
for dest in notification_urls:
status = self.apprise.add(dest)
# we tag the url so it only sends each notification once
tag = str(event.event_id)
tags.append(tag)
status = self.apprise.add(dest, tag=tag)
if not status and self.hard_fail:
raise Exception("Apprise URL Add Failed")
self.apprise.notify(title=event.title, body=event.body)
self.apprise.notify(title=event.message.title, body=event.message.body, tag=tags)