Skip to content

Commit

Permalink
used anyOf for scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
ychebyshev committed Mar 26, 2024
1 parent 6564719 commit e309a35
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion shvatka/infrastructure/scheduler/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ScheduledContextHolder:
ATTENTION!
GLOBAL VARIABLE!
"""

dishka: AsyncContainer


Expand Down
6 changes: 3 additions & 3 deletions shvatka/infrastructure/scheduler/factory.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
6 changes: 2 additions & 4 deletions shvatka/infrastructure/scheduler/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)

0 comments on commit e309a35

Please sign in to comment.