Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit c7ded99

Browse files
Updated reset_notification_timer.py and timer.py to update timer hours, minutes, and seconds to zero (#188)
1 parent 5640a6f commit c7ded99

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

edx_notifications/management/commands/reset_notification_timer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def cancel_old_notification_timers(self):
6868
self.store.save_notification_timer(timer)
6969

7070
def reset_digest_notification_timer(self):
71+
"""
72+
Gets old timers of daily and weekly digests and update callback_at value with current
73+
UTC datetime and add timedelta and last_ran value with current UTC datetime to avoid
74+
sending old notification digest emails to users.
75+
"""
7176
context = {
7277
'last_ran': datetime.now(pytz.UTC),
7378
}
@@ -81,6 +86,8 @@ def reset_digest_notification_timer(self):
8186
if digest_timer.periodicity_min
8287
else const.MINUTES_IN_A_DAY)
8388
digest_timer.callback_at = datetime.now(pytz.UTC) + timedelta(minutes=rerun_delta)
89+
digest_timer.callback_at = digest_timer.callback_at.replace(hour=0, minute=0,
90+
second=0, microsecond=0)
8491
digest_timer.context.update(context)
8592

8693
self.store.save_notification_timer(digest_timer)
@@ -96,6 +103,8 @@ def reset_digest_notification_timer(self):
96103
if digest_timer.periodicity_min
97104
else const.MINUTES_IN_A_WEEK)
98105
digest_timer.callback_at = datetime.now(pytz.UTC) + timedelta(minutes=rerun_delta)
106+
digest_timer.callback_at = digest_timer.callback_at.replace(hour=0, minute=0,
107+
second=0, microsecond=0)
99108
digest_timer.context.update(context)
100109

101110
self.store.save_notification_timer(digest_timer)

edx_notifications/tests/test_timer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,6 @@ def test_purge_timer_rescheduling(self):
588588

589589
# allow for some slight time arthimetic skew
590590
expected_callback_at = purge_notifications_timer.callback_at.replace(second=0, microsecond=0)
591-
actual_callback_at = (reset_time + timedelta(days=1)).replace(second=0, microsecond=0)
591+
actual_callback_at = (reset_time + timedelta(days=1)).replace(hour=0, second=0, microsecond=0)
592592

593593
self.assertEqual(expected_callback_at, actual_callback_at)

edx_notifications/timer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def poll_and_execute_timers(**kwargs): # pylint: disable=unused-argument
7070
if timer.callback_at < datetime.now(pytz.UTC):
7171
timer.callback_at = datetime.now(pytz.UTC) + timedelta(minutes=rerun_delta)
7272

73+
timer.callback_at = timer.callback_at.replace(hour=0, minute=0, second=0,
74+
microsecond=0)
75+
7376
timer.executed_at = None # need to reset this or it won't get picked up again
7477

7578
if results.get('errors'):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def load_requirements(*requirements_paths):
3434

3535
setup(
3636
name='edx-notifications',
37-
version='0.8.2',
37+
version='0.8.3',
3838
description='Notification subsystem for Open edX',
3939
long_description=open('README.md').read(),
4040
author='edX',

0 commit comments

Comments
 (0)