This commit is contained in:
itqop 2026-02-17 14:13:19 +03:00
parent 987f3e6609
commit 2bd74a5341
3 changed files with 11 additions and 15 deletions

View File

@ -78,6 +78,12 @@ async def check_and_send_reminders(bot: Bot) -> None:
current_run=reminder.next_run_at, current_run=reminder.next_run_at,
days_interval=reminder.days_interval, days_interval=reminder.days_interval,
) )
next_run = next_run.replace(
hour=reminder.time_of_day.hour,
minute=reminder.time_of_day.minute,
second=0,
microsecond=0,
)
reminder.next_run_at = next_run reminder.next_run_at = next_run
reminder.updated_at = time_service.get_now() reminder.updated_at = time_service.get_now()

View File

@ -244,15 +244,14 @@ async def delete_reminder(session: AsyncSession, reminder_id: int) -> bool:
async def mark_reminder_done( async def mark_reminder_done(
session: AsyncSession, session: AsyncSession,
reminder_id: int, reminder_id: int,
next_run_at: datetime,
) -> Optional[Reminder]: ) -> Optional[Reminder]:
""" """
Mark reminder as done and schedule next run. Mark reminder as done. Does not touch next_run_at the scheduler
already advanced it when the notification was sent.
Args: Args:
session: Database session session: Database session
reminder_id: Reminder ID reminder_id: Reminder ID
next_run_at: Next execution datetime
Returns: Returns:
Updated Reminder instance or None Updated Reminder instance or None
@ -262,7 +261,6 @@ async def mark_reminder_done(
return None return None
reminder.last_done_at = _now_local() reminder.last_done_at = _now_local()
reminder.next_run_at = next_run_at
reminder.total_done_count += 1 reminder.total_done_count += 1
reminder.updated_at = _now_local() reminder.updated_at = _now_local()

View File

@ -212,7 +212,8 @@ class RemindersService:
reminder_id: int, reminder_id: int,
) -> Optional[Reminder]: ) -> Optional[Reminder]:
""" """
Mark reminder as done and schedule next occurrence. Mark reminder as done. Does not recalculate next_run_at because
the scheduler already advanced it when sending the notification.
Args: Args:
session: Database session session: Database session
@ -221,16 +222,7 @@ class RemindersService:
Returns: Returns:
Updated Reminder instance or None Updated Reminder instance or None
""" """
reminder = await get_reminder_by_id(session, reminder_id) return await mark_reminder_done(session, reminder_id)
if not reminder:
return None
next_run_at = self.time_service.calculate_next_occurrence(
current_run=reminder.next_run_at,
days_interval=reminder.days_interval,
)
return await mark_reminder_done(session, reminder_id, next_run_at)
async def snooze( async def snooze(
self, self,