|
4 | 4 | import logging
|
5 | 5 | import uuid
|
6 | 6 | from abc import ABC
|
7 |
| -from typing import Awaitable, Optional |
| 7 | +from typing import Awaitable, Literal, Optional, TypeAlias |
8 | 8 |
|
9 |
| -from aiohttp import BasicAuth, ClientSession, ClientTimeout |
| 9 | +from aiohttp import BasicAuth, ClientResponseError, ClientSession, ClientTimeout |
10 | 10 | from more_itertools import chunked
|
11 | 11 | from yarl import URL
|
12 | 12 |
|
|
17 | 17 |
|
18 | 18 | _logger = logging.getLogger(__name__)
|
19 | 19 |
|
| 20 | +DomainModelType: TypeAlias = Literal["Prozess", "Aufgabe", "Zeitlimit"] |
| 21 | + |
20 | 22 |
|
21 | 23 | class BssClient(ABC):
|
22 | 24 | """
|
@@ -154,6 +156,29 @@ async def get_all_ermittlungsauftraege(self, package_size: int = 100) -> list[Er
|
154 | 156 | _logger.info("Downloaded %i Ermittlungsautraege", len(result))
|
155 | 157 | return result
|
156 | 158 |
|
| 159 | + async def replay_event(self, model_type: DomainModelType, model_id: uuid.UUID, event_number: int) -> bool: |
| 160 | + """calls the re-apply endpoint""" |
| 161 | + session = await self._get_session() |
| 162 | + request_url = ( |
| 163 | + self._config.server_url |
| 164 | + / "api" |
| 165 | + / "Event" |
| 166 | + / "replay" |
| 167 | + / model_type |
| 168 | + / str(model_id) |
| 169 | + / str(event_number) |
| 170 | + / "false" # is temporal |
| 171 | + ) |
| 172 | + request_uuid = uuid.uuid4() |
| 173 | + _logger.debug("[%s] requesting %s", str(request_uuid), request_url) |
| 174 | + try: |
| 175 | + async with session.patch(request_url) as response: |
| 176 | + _logger.debug("[%s] response status: %s", str(request_uuid), response.status) |
| 177 | + return response.status == 200 |
| 178 | + except ClientResponseError as cre: |
| 179 | + _logger.debug("[%s] response status: %s", str(request_uuid), cre.status) |
| 180 | + return False |
| 181 | + |
157 | 182 |
|
158 | 183 | class BasicAuthBssClient(BssClient):
|
159 | 184 | """BSS client with basic auth"""
|
|
0 commit comments