Generics & visitor pattern?
This commit is contained in:
parent
3845cc7ecf
commit
1440ec51b7
4 changed files with 33 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import uuid
|
||||
from typing import Annotated
|
||||
from typing import Annotated, List
|
||||
|
||||
from injectable import injectable, autowired, Autowired
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ from app.model.healthcheck import HealthCheck
|
|||
from app.model.webhook import WebhookEvent
|
||||
from app.services import DockerService, GitService, Passwords
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@injectable(singleton=True)
|
||||
class WebhookProcessor(EnqueuedProcessor):
|
||||
|
|
@ -24,7 +26,21 @@ class WebhookProcessor(EnqueuedProcessor):
|
|||
def enqueue(self, event: WebhookEvent):
|
||||
self._enqueue(Task(uuid.UUID(), self, event))
|
||||
|
||||
def _process(self, task: Task) -> Result:
|
||||
def _process(self, task: Task[WebhookEvent]) -> Result:
|
||||
event: WebhookEvent = task.payload
|
||||
# TODO: persist event data
|
||||
commit_hash = self._git.get_new_commit_hash()
|
||||
if commit_hash != event.commit:
|
||||
logger.warning(f"Commit hash mismatch: {commit_hash} != {event.commit}")
|
||||
return Result(task.id, False, "Commit hash mismatch")
|
||||
# TODO: persist commit data
|
||||
service = self._get_service(event.files)
|
||||
|
||||
|
||||
|
||||
return Result(task.id, True)
|
||||
|
||||
def _get_service(self, files: List[str]) -> str:
|
||||
pass
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@ import uuid
|
|||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from multiprocessing import Queue, Process
|
||||
from typing import TypeVar
|
||||
|
||||
from injectable import injectable
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
@dataclass
|
||||
class Task:
|
||||
_id: uuid.UUID
|
||||
class Task[T]:
|
||||
id: uuid.UUID
|
||||
processor: 'EnqueuedProcessor'
|
||||
payload: object
|
||||
payload: T
|
||||
|
||||
@dataclass
|
||||
class Result:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue