Event bus basics
This commit is contained in:
parent
1440ec51b7
commit
87e8af3f72
8 changed files with 88 additions and 16 deletions
|
|
@ -3,6 +3,7 @@ import uuid
|
|||
from typing import Annotated, List
|
||||
|
||||
from injectable import injectable, autowired, Autowired
|
||||
from typing_extensions import deprecated
|
||||
|
||||
from app.core.queue import EnqueuedProcessor, ProcessQueue, Task, Result
|
||||
from app.model.healthcheck import HealthCheck
|
||||
|
|
@ -11,20 +12,19 @@ from app.services import DockerService, GitService, Passwords
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@deprecated("Use event bus instead.")
|
||||
@injectable(singleton=True)
|
||||
class WebhookProcessor(EnqueuedProcessor):
|
||||
class WebhookProcessor:
|
||||
@autowired
|
||||
def __init__(self, docker: Annotated[DockerService, Autowired],
|
||||
git: Annotated[GitService, Autowired],
|
||||
keepass: Annotated[Passwords, Autowired],
|
||||
queue: Annotated[ProcessQueue, Autowired]):
|
||||
super().__init__(queue)
|
||||
keepass: Annotated[Passwords, Autowired]):
|
||||
self._docker = docker
|
||||
self._git = git
|
||||
self._keepass = keepass
|
||||
|
||||
def enqueue(self, event: WebhookEvent):
|
||||
self._enqueue(Task(uuid.UUID(), self, event))
|
||||
pass
|
||||
|
||||
def _process(self, task: Task[WebhookEvent]) -> Result:
|
||||
event: WebhookEvent = task.payload
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from injectable import inject
|
||||
|
||||
from app.core.core import WebhookProcessor
|
||||
from app.events import SimpleEventBus
|
||||
|
||||
|
||||
class AutowireSupport:
|
||||
|
|
@ -8,3 +9,7 @@ class AutowireSupport:
|
|||
@staticmethod
|
||||
def webhook_processor():
|
||||
return inject(WebhookProcessor)
|
||||
|
||||
@staticmethod
|
||||
def event_bus():
|
||||
return inject(SimpleEventBus)
|
||||
|
|
|
|||
22
app/core/woodpecker.py
Normal file
22
app/core/woodpecker.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import logging
|
||||
|
||||
from injectable import injectable
|
||||
|
||||
from app.events import SimpleEventBus
|
||||
from app.model.webhook import WebhookEvent
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@injectable
|
||||
class Woodpecker:
|
||||
|
||||
@SimpleEventBus.on(WebhookEvent)
|
||||
def on_event(self, event): # TODO: caller nie działa -> brakuje instancji klasy?
|
||||
logger.info(f"Received event: {event}")
|
||||
pass
|
||||
|
||||
|
||||
@SimpleEventBus.on(WebhookEvent)
|
||||
def on_event2(event): # TODO: Tu działa
|
||||
logger.info(f"F2: Received event: {event}")
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue