Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
deferred_work: Re-queue remaining "mark all as read" work after 30s.
Alex Vandiver58f06699971e
diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.pyindex aa022608841..f27c36eaa3d 100644--- a/zerver/worker/queue_processors.py+++ b/zerver/worker/queue_processors.py@@ -78,7 +78,7 @@ from zerver.lib.push_notifications import (initialize_push_notifications,)from zerver.lib.pysa import mark_sanitized-from zerver.lib.queue import SimpleQueueClient, retry_event+from zerver.lib.queue import SimpleQueueClient, queue_json_publish, retry_eventfrom zerver.lib.remote_server import (PushNotificationBouncerRetryLaterError,send_server_data_to_push_bouncer,@@ -1061,7 +1061,8 @@ class DeferredWorker(QueueProcessingWorker):stream = Stream.objects.get(recipient_id=event["stream_recipient_id"])# This event is generated by the stream deactivation code path.batch_size = 100- offset = 0+ offset = event.get("offset", 0)+ start_time = time.perf_counter()while True:with transaction.atomic(savepoint=False):# Note that this algorithm is susceptible to@@ -1087,9 +1088,18 @@ class DeferredWorker(QueueProcessingWorker):offset += message_countif message_count < batch_size:break+ if time.perf_counter() - start_time > 30:+ # This task may take a _very_ long time to+ # complete, if we have a large number of messages+ # to mark as read. If we have taken more than+ # 30s, we re-push the task onto the tail of the+ # queue, to allow other deferred work to complete;+ # this task is extremely low priority.+ queue_json_publish("deferred_work", {**event, "offset": offset})+ breaklogger.info("Marked %s messages as read for all users, stream_recipient_id %s",- offset,+ offset - event.get("offset", 0),event["stream_recipient_id"],)elif event["type"] == "clear_push_device_tokens":