mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Extract process_one_batch() in SlowQueryWorker.
By extracting the function, we eliminate a redundant sleep call. (imported from commit 24d4485019f96ae10e9a00244643b77ff2a7db57)
This commit is contained in:
@@ -213,24 +213,25 @@ class FeedbackBot(QueueProcessingWorker):
|
|||||||
class SlowQueryWorker(QueueProcessingWorker):
|
class SlowQueryWorker(QueueProcessingWorker):
|
||||||
def start(self):
|
def start(self):
|
||||||
while True:
|
while True:
|
||||||
if settings.ERROR_BOT is None:
|
self.process_one_batch()
|
||||||
time.sleep(1 * 60)
|
|
||||||
continue
|
|
||||||
|
|
||||||
slow_queries = self.q.drain_queue("slow_queries", json=True)
|
|
||||||
|
|
||||||
if len(slow_queries) > 0:
|
|
||||||
topic = "%s: slow queries" % (settings.STATSD_PREFIX,)
|
|
||||||
|
|
||||||
content = ""
|
|
||||||
for query in slow_queries:
|
|
||||||
content += " %s\n" % (query,)
|
|
||||||
|
|
||||||
internal_send_message(settings.ERROR_BOT, "stream", "logs", topic, content)
|
|
||||||
|
|
||||||
# Aggregate all slow query messages in 1-minute chunks to avoid message spam
|
# Aggregate all slow query messages in 1-minute chunks to avoid message spam
|
||||||
time.sleep(1 * 60)
|
time.sleep(1 * 60)
|
||||||
|
|
||||||
|
def process_one_batch(self):
|
||||||
|
if settings.ERROR_BOT is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
slow_queries = self.q.drain_queue("slow_queries", json=True)
|
||||||
|
|
||||||
|
if len(slow_queries) > 0:
|
||||||
|
topic = "%s: slow queries" % (settings.STATSD_PREFIX,)
|
||||||
|
|
||||||
|
content = ""
|
||||||
|
for query in slow_queries:
|
||||||
|
content += " %s\n" % (query,)
|
||||||
|
|
||||||
|
internal_send_message(settings.ERROR_BOT, "stream", "logs", topic, content)
|
||||||
|
|
||||||
@assign_queue("message_sender")
|
@assign_queue("message_sender")
|
||||||
class MessageSenderWorker(QueueProcessingWorker):
|
class MessageSenderWorker(QueueProcessingWorker):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user