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.

embed_links: Interrupt consume() function on worker timeout.

Mateusz Mandera58d9975cca88
diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py
index 53fcd33b5d4..556be5a5cac 100644
--- a/zerver/worker/queue_processors.py
+++ b/zerver/worker/queue_processors.py
@@ -115,6 +115,16 @@ class WorkerTimeoutException(Exception):
return f"Timed out after {self.limit * self.event_count} seconds processing {self.event_count} events"
+class InterruptConsumeException(Exception):
+ """
+ This exception is to be thrown inside event consume function
+ if the intention is to simply interrupt the processing
+ of the current event and normally continue the work of the queue.
+ """
+
+ pass
+
+
class WorkerDeclarationException(Exception):
pass
@@ -341,6 +351,11 @@ class QueueProcessingWorker(ABC):
raise WorkerTimeoutException(limit, len(events))
def _handle_consume_exception(self, events: List[Dict[str, Any]], exception: Exception) -> None:
+ if isinstance(exception, InterruptConsumeException):
+ # The exception signals that no further error handling
+ # is needed and the worker can proceed.
+ return
+
with configure_scope() as scope:
scope.set_context(
"events",
@@ -775,6 +790,7 @@ class FetchLinksEmbedData(QueueProcessingWorker):
event["message_id"],
event["urls"],
)
+ raise InterruptConsumeException
@assign_queue("outgoing_webhooks")