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

@@ -35,7 +35,7 @@ router = APIRouter(
@controller(router)
class GroupEventsNotifierController(BaseUserController):
event_bus: EventBusService = Depends(EventBusService)
event_bus: EventBusService = Depends(EventBusService.create)
@cached_property
def repo(self):

View File

@@ -1,3 +1,4 @@
from datetime import datetime
from functools import cached_property
from fastapi import APIRouter, Depends
@@ -9,6 +10,7 @@ from mealie.routes._base.mixins import HttpRepo
from mealie.schema import mapper
from mealie.schema.group.webhook import CreateWebhook, ReadWebhook, SaveWebhook, WebhookPagination
from mealie.schema.response.pagination import PaginationQuery
from mealie.services.scheduler.tasks.post_webhooks import post_group_webhooks
router = APIRouter(prefix="/groups/webhooks", tags=["Groups: Webhooks"])
@@ -38,6 +40,14 @@ class ReadWebhookController(BaseUserController):
save = mapper.cast(data, SaveWebhook, group_id=self.group.id)
return self.mixins.create_one(save)
@router.post("/rerun")
def rerun_webhooks(self):
"""Manually re-fires all previously scheduled webhooks for today"""
start_time = datetime.min.time()
start_dt = datetime.combine(datetime.utcnow().date(), start_time)
post_group_webhooks(start_dt=start_dt, group_id=self.group.id)
@router.get("/{item_id}", response_model=ReadWebhook)
def get_one(self, item_id: UUID4):
return self.mixins.get_one(item_id)