From e309a35a5fcea1d17e6666be020a58369916c6e0 Mon Sep 17 00:00:00 2001 From: ychebyshev Date: Tue, 26 Mar 2024 23:28:04 +0300 Subject: [PATCH] used anyOf for scheduler --- shvatka/infrastructure/scheduler/context.py | 1 - shvatka/infrastructure/scheduler/factory.py | 6 +++--- shvatka/infrastructure/scheduler/wrappers.py | 6 ++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/shvatka/infrastructure/scheduler/context.py b/shvatka/infrastructure/scheduler/context.py index af280a35..2fa7fadf 100644 --- a/shvatka/infrastructure/scheduler/context.py +++ b/shvatka/infrastructure/scheduler/context.py @@ -7,7 +7,6 @@ class ScheduledContextHolder: ATTENTION! GLOBAL VARIABLE! """ - dishka: AsyncContainer diff --git a/shvatka/infrastructure/scheduler/factory.py b/shvatka/infrastructure/scheduler/factory.py index 8453f5b3..cd5d716f 100644 --- a/shvatka/infrastructure/scheduler/factory.py +++ b/shvatka/infrastructure/scheduler/factory.py @@ -1,8 +1,8 @@ from typing import AsyncIterable -from dishka import Provider, Scope, provide, AsyncContainer +from dishka import Provider, Scope, provide, AsyncContainer, AnyOf -from shvatka.core.interfaces.scheduler import Scheduler +from shvatka.core.interfaces.scheduler import Scheduler, LevelTestScheduler from shvatka.infrastructure.db.config.models.db import RedisConfig from shvatka.infrastructure.scheduler import ApScheduler @@ -13,6 +13,6 @@ class SchedulerProvider(Provider): @provide async def create_scheduler( self, dishka: AsyncContainer, redis_config: RedisConfig - ) -> AsyncIterable[Scheduler]: + ) -> AsyncIterable[AnyOf[Scheduler, LevelTestScheduler]]: async with ApScheduler(dishka=dishka, redis_config=redis_config) as scheduler: yield scheduler diff --git a/shvatka/infrastructure/scheduler/wrappers.py b/shvatka/infrastructure/scheduler/wrappers.py index 4be27796..c809f635 100644 --- a/shvatka/infrastructure/scheduler/wrappers.py +++ b/shvatka/infrastructure/scheduler/wrappers.py @@ -86,7 +86,7 @@ async def send_hint_for_testing_wrapper( dao: FromDishka[HolderDao], bot: FromDishka[Bot], file_storage: FromDishka[FileStorage], - scheduler: FromDishka[Scheduler], + scheduler: FromDishka[LevelTestScheduler], ): level = await dao.level.get_by_id(level_id) game = await dao.game.get_by_id(game_id) @@ -97,8 +97,6 @@ async def send_hint_for_testing_wrapper( suite=dto.LevelTestSuite(level=level, tester=org), hint_number=hint_number, view=create_level_test_view(bot, dao, file_storage), - scheduler=typing.cast( - LevelTestScheduler, scheduler - ), # TODO typing.cast replace with better hint + scheduler=scheduler, dao=dao.level_testing_complex, )