|
1 | 1 | import asyncio |
2 | 2 | import logging |
3 | 3 | from collections.abc import AsyncIterator, Iterable |
4 | | -from contextlib import asynccontextmanager, suppress |
| 4 | +from contextlib import suppress |
5 | 5 | from datetime import timedelta |
6 | 6 | from typing import Final |
7 | 7 | from uuid import uuid4 |
8 | 8 |
|
9 | | -from common_library.error_codes import create_error_code |
10 | | -from common_library.logging.logging_errors import create_troubleshooting_log_kwargs |
11 | 9 | from fastapi import FastAPI |
12 | 10 | from fastapi_lifespan_manager import State |
13 | 11 | from pydantic import NonNegativeInt |
|
23 | 21 | get_steps_statuses, |
24 | 22 | is_operation_in_progress_status, |
25 | 23 | raise_if_overwrites_any_operation_provided_key, |
| 24 | + safe_event, |
26 | 25 | set_unexpected_opration_state, |
27 | 26 | start_and_mark_as_started, |
28 | 27 | start_steps_and_get_count, |
@@ -112,33 +111,6 @@ async def start_operation( |
112 | 111 | await enqueue_schedule_event(self.app, schedule_id) |
113 | 112 | return schedule_id |
114 | 113 |
|
115 | | - @asynccontextmanager |
116 | | - async def _safe_event(self, schedule_id: ScheduleId) -> AsyncIterator[None]: |
117 | | - try: |
118 | | - yield |
119 | | - except KeyNotFoundInHashError as err: |
120 | | - _logger.debug( |
121 | | - "Cannot process schedule_id='%s' since it's data was not found: %s", |
122 | | - schedule_id, |
123 | | - err, |
124 | | - ) |
125 | | - except Exception as err: # pylint:disable=broad-exception-caught |
126 | | - error_code = create_error_code(err) |
127 | | - log_kwargs = create_troubleshooting_log_kwargs( |
128 | | - "Unexpected error druing scheduling", |
129 | | - error=err, |
130 | | - error_code=error_code, |
131 | | - error_context={"schedule_id": schedule_id}, |
132 | | - tip="This is a bug, please report it to the developers", |
133 | | - ) |
134 | | - _logger.exception(**log_kwargs) |
135 | | - await set_unexpected_opration_state( |
136 | | - self._store, |
137 | | - schedule_id, |
138 | | - OperationErrorType.FRAMEWORK_ISSUE, |
139 | | - message=log_kwargs["msg"], |
140 | | - ) |
141 | | - |
142 | 114 | async def cancel_schedule(self, schedule_id: ScheduleId) -> None: |
143 | 115 | """ |
144 | 116 | Cancels and runs destruction of the operation |
@@ -291,7 +263,7 @@ async def restart_operation_step_in_error( |
291 | 263 | ) |
292 | 264 |
|
293 | 265 | async def safe_on_schedule_event(self, schedule_id: ScheduleId) -> None: |
294 | | - async with self._safe_event(schedule_id): |
| 266 | + async with safe_event(self._store, schedule_id): |
295 | 267 | await self._on_schedule_event(schedule_id) |
296 | 268 |
|
297 | 269 | async def _on_schedule_event(self, schedule_id: ScheduleId) -> None: |
|
0 commit comments