fix: добавить детальное логирование проведения розыгрыша для диагностики
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
@@ -264,10 +264,16 @@ class LotteryService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
async def conduct_draw(session: AsyncSession, lottery_id: int) -> Dict[int, Dict[str, Any]]:
|
async def conduct_draw(session: AsyncSession, lottery_id: int) -> Dict[int, Dict[str, Any]]:
|
||||||
"""Провести розыгрыш с учетом ручных победителей"""
|
"""Провести розыгрыш с учетом ручных победителей"""
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
logger.info(f"conduct_draw: начало для lottery_id={lottery_id}")
|
||||||
lottery = await LotteryService.get_lottery(session, lottery_id)
|
lottery = await LotteryService.get_lottery(session, lottery_id)
|
||||||
if not lottery or lottery.is_completed:
|
if not lottery or lottery.is_completed:
|
||||||
|
logger.warning(f"conduct_draw: lottery не найден или завершён")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
logger.info(f"conduct_draw: получаем участников")
|
||||||
# Получаем всех участников (включая тех, у кого нет user)
|
# Получаем всех участников (включая тех, у кого нет user)
|
||||||
participants = []
|
participants = []
|
||||||
for p in lottery.participations:
|
for p in lottery.participations:
|
||||||
@@ -282,7 +288,9 @@ class LotteryService:
|
|||||||
'account_number': p.account_number
|
'account_number': p.account_number
|
||||||
})())
|
})())
|
||||||
|
|
||||||
|
logger.info(f"conduct_draw: участников {len(participants)}")
|
||||||
if not participants:
|
if not participants:
|
||||||
|
logger.warning(f"conduct_draw: нет участников")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# Определяем количество призовых мест
|
# Определяем количество призовых мест
|
||||||
@@ -336,6 +344,7 @@ class LotteryService:
|
|||||||
session.add(winner)
|
session.add(winner)
|
||||||
|
|
||||||
# Обновляем статус розыгрыша
|
# Обновляем статус розыгрыша
|
||||||
|
logger.info(f"conduct_draw: обновляем статус lottery")
|
||||||
lottery.is_completed = True
|
lottery.is_completed = True
|
||||||
lottery.draw_results = {}
|
lottery.draw_results = {}
|
||||||
for place, info in results.items():
|
for place, info in results.items():
|
||||||
@@ -349,7 +358,9 @@ class LotteryService:
|
|||||||
'is_manual': info['is_manual']
|
'is_manual': info['is_manual']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(f"conduct_draw: коммитим изменения")
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
logger.info(f"conduct_draw: успешно завершено, победителей: {len(results)}")
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -2701,7 +2701,14 @@ async def conduct_lottery_draw(callback: CallbackQuery):
|
|||||||
await callback.answer("⏳ Проводится розыгрыш...", show_alert=True)
|
await callback.answer("⏳ Проводится розыгрыш...", show_alert=True)
|
||||||
|
|
||||||
# Проводим розыгрыш через сервис
|
# Проводим розыгрыш через сервис
|
||||||
winners_dict = await LotteryService.conduct_draw(session, lottery_id)
|
logger.info(f"Начинаем проведение розыгрыша {lottery_id}")
|
||||||
|
try:
|
||||||
|
winners_dict = await LotteryService.conduct_draw(session, lottery_id)
|
||||||
|
logger.info(f"Розыгрыш {lottery_id} проведён, победителей: {len(winners_dict)}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Ошибка при проведении розыгрыша {lottery_id}: {e}", exc_info=True)
|
||||||
|
await callback.answer(f"❌ Ошибка: {e}", show_alert=True)
|
||||||
|
return
|
||||||
|
|
||||||
if winners_dict:
|
if winners_dict:
|
||||||
# Отправляем уведомления победителям
|
# Отправляем уведомления победителям
|
||||||
|
|||||||
Reference in New Issue
Block a user