mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 10:25:28 +03:00
commit
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import logging
|
||||
|
||||
from dishka import AsyncContainer
|
||||
|
||||
from trudex.infrastructure.database.dao.test import TestDAO
|
||||
from trudex.infrastructure.utils.timezone import now_msk_naive
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def deactivate_expired_tests(container: AsyncContainer):
|
||||
|
||||
async def deactivate_expired_tests(container: AsyncContainer) -> None:
|
||||
async with container() as request_container:
|
||||
test_dao = await request_container.get(TestDAO)
|
||||
|
||||
tests = await test_dao.get_all()
|
||||
expired_tests = await test_dao.get_expired_active_tests(now_msk_naive())
|
||||
|
||||
for test in tests:
|
||||
if test.expires_at and test.expires_at < now_msk_naive() and test.is_active:
|
||||
await test_dao.update(test.id, is_active=False)
|
||||
for test in expired_tests:
|
||||
await test_dao.update(test.id, is_active=False)
|
||||
logger.info("Деактивирован истёкший тест: id=%d, title=%s", test.id, test.title)
|
||||
|
||||
Reference in New Issue
Block a user