MissedMessageWorker: Use custom batching periods from UserProfile.

This commit is contained in:
Abhijeet Prasad Bodas 2021-07-19 14:34:18 +05:30 committed by Tim Abbott
parent d5d3f14eee
commit dd5e12d112
2 changed files with 10 additions and 3 deletions

View File

@ -178,7 +178,13 @@ class WorkerTest(ZulipTestCase):
fake_client.enqueue("missedmessage_emails", event)
mmw = MissedMessageWorker()
batch_duration = datetime.timedelta(seconds=mmw.BATCH_DURATION)
batch_duration = datetime.timedelta(
seconds=hamlet.email_notifications_batching_period_seconds
)
assert (
hamlet.email_notifications_batching_period_seconds
== othello.email_notifications_batching_period_seconds
)
class MockTimer:
is_running = False

View File

@ -564,7 +564,6 @@ class MissedMessageWorker(QueueProcessingWorker):
# The timer is running whenever; we poll at most every TIMER_FREQUENCY
# seconds, to avoid excessive activity.
TIMER_FREQUENCY = 5
BATCH_DURATION = 120
timer_event: Optional[Timer] = None
# This lock protects access to all of the data structures declared
@ -586,7 +585,9 @@ class MissedMessageWorker(QueueProcessingWorker):
# When we consume an event, check if there are existing pending emails
# for that user, and if so use the same scheduled timestamp.
user_profile_id: int = event["user_profile_id"]
batch_duration = datetime.timedelta(seconds=self.BATCH_DURATION)
user_profile = get_user_profile_by_id(user_profile_id)
batch_duration_seconds = user_profile.email_notifications_batching_period_seconds
batch_duration = datetime.timedelta(seconds=batch_duration_seconds)
try:
pending_email = ScheduledMessageNotificationEmail.objects.filter(