fix notifications
This commit is contained in:
parent
24d53e731a
commit
9cb573db7d
1 changed files with 13 additions and 11 deletions
|
|
@ -1153,8 +1153,8 @@ class LichessBot:
|
||||||
"""Periodic check for gamer activity"""
|
"""Periodic check for gamer activity"""
|
||||||
task_key = f"{gamer['id']}_{user_id}"
|
task_key = f"{gamer['id']}_{user_id}"
|
||||||
|
|
||||||
# Запоминаем время начала отслеживания
|
# Запоминаем время начала отслеживания (текущее время минус период, чтобы сразу проверить последний период)
|
||||||
start_time = datetime.now()
|
start_time = datetime.now() - timedelta(minutes=period_minutes)
|
||||||
self.period_start_times[task_key] = start_time
|
self.period_start_times[task_key] = start_time
|
||||||
logger.info(f"Started periodic monitoring for {gamer['username']} with {period_minutes} minute intervals")
|
logger.info(f"Started periodic monitoring for {gamer['username']} with {period_minutes} minute intervals")
|
||||||
|
|
||||||
|
|
@ -1190,15 +1190,17 @@ class LichessBot:
|
||||||
# Ждем заданное количество минут
|
# Ждем заданное количество минут
|
||||||
await asyncio.sleep(period_minutes * 60)
|
await asyncio.sleep(period_minutes * 60)
|
||||||
|
|
||||||
# Получаем время начала периода
|
# Получаем время начала периода (время последней проверки или время старта задачи)
|
||||||
period_start = self.period_start_times.get(task_key, start_time)
|
period_start = self.period_start_times.get(task_key, start_time)
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
# Рассчитываем timestamps в миллисекундах
|
# Рассчитываем период: от (текущее время - период) до текущего времени
|
||||||
since_timestamp = int(period_start.timestamp() * 1000)
|
# Это гарантирует, что мы проверяем последний час активности
|
||||||
|
since_time = now - timedelta(minutes=period_minutes)
|
||||||
|
since_timestamp = int(since_time.timestamp() * 1000)
|
||||||
until_timestamp = int(now.timestamp() * 1000)
|
until_timestamp = int(now.timestamp() * 1000)
|
||||||
|
|
||||||
logger.info(f"Checking period for {gamer['username']}: {period_start} to {now}")
|
logger.info(f"Checking period for {gamer['username']}: {since_time} to {now} (last {period_minutes} minutes)")
|
||||||
logger.info(f"Unix timestamps: since={since_timestamp}, until={until_timestamp}")
|
logger.info(f"Unix timestamps: since={since_timestamp}, until={until_timestamp}")
|
||||||
|
|
||||||
# Делаем запросы к API с обработкой ошибок
|
# Делаем запросы к API с обработкой ошибок
|
||||||
|
|
@ -1265,7 +1267,7 @@ class LichessBot:
|
||||||
text=notification
|
text=notification
|
||||||
)
|
)
|
||||||
logger.info(f"✅ Sent periodic notification for {gamer['username']} to user {user_id}")
|
logger.info(f"✅ Sent periodic notification for {gamer['username']} to user {user_id}")
|
||||||
# Обновляем время начала только после успешной отправки уведомления
|
# Обновляем время начала на текущее время после успешной отправки уведомления
|
||||||
self.period_start_times[task_key] = now
|
self.period_start_times[task_key] = now
|
||||||
# Increment periodic notification counter
|
# Increment periodic notification counter
|
||||||
self.counters.increment('periodic_notification')
|
self.counters.increment('periodic_notification')
|
||||||
|
|
@ -1286,7 +1288,7 @@ class LichessBot:
|
||||||
self.period_start_times[task_key] = now
|
self.period_start_times[task_key] = now
|
||||||
else:
|
else:
|
||||||
logger.debug(f"⏭️ No activity found for {gamer['username']} in the last {period_minutes} minutes")
|
logger.debug(f"⏭️ No activity found for {gamer['username']} in the last {period_minutes} minutes")
|
||||||
# Обновляем время начала даже если нет активности, чтобы не зацикливаться
|
# Обновляем время начала на текущее время даже если нет активности
|
||||||
self.period_start_times[task_key] = now
|
self.period_start_times[task_key] = now
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue