Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

MissedMessageWorker: Use custom batching periods from UserProfile.

Abhijeet Prasad Bodasdd5e12d11281
diff --git a/zerver/tests/test_queue_worker.py b/zerver/tests/test_queue_worker.py
index e6778743a31..692f9c579d1 100644
--- a/zerver/tests/test_queue_worker.py
+++ b/zerver/tests/test_queue_worker.py
@@ -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
diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py
index e9b3d4f9c3d..5d656d76b71 100644
--- a/zerver/worker/queue_processors.py
+++ b/zerver/worker/queue_processors.py
@@ -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(