2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-09-11 19:58:58 +02:00
|
|
|
from django.core.management import CommandError
|
2017-11-16 00:43:27 +01:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2013-09-11 19:58:58 +02:00
|
|
|
from zerver.lib.queue import SimpleQueueClient
|
2017-06-05 07:47:03 +02:00
|
|
|
from zerver.worker.queue_processors import get_active_worker_queues
|
2013-09-11 19:58:58 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2013-09-11 19:58:58 +02:00
|
|
|
class Command(BaseCommand):
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2017-06-05 07:47:03 +02:00
|
|
|
parser.add_argument(dest="queue_name", type=str, nargs='?',
|
|
|
|
help="queue to purge", default=None)
|
|
|
|
parser.add_argument('--all', dest="all", action="store_true",
|
|
|
|
default=False, help="purge all queues")
|
2015-08-21 02:10:41 +02:00
|
|
|
|
2013-09-11 19:58:58 +02:00
|
|
|
help = "Discards all messages from the given queue"
|
2016-11-29 07:22:02 +01:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
|
|
|
def purge_queue(queue_name: str) -> None:
|
2017-06-05 07:47:03 +02:00
|
|
|
queue = SimpleQueueClient()
|
2020-07-05 03:18:11 +02:00
|
|
|
queue.ensure_queue(queue_name, lambda channel: channel.queue_purge(queue_name))
|
2017-06-05 07:47:03 +02:00
|
|
|
|
|
|
|
if options['all']:
|
|
|
|
for queue_name in get_active_worker_queues():
|
|
|
|
purge_queue(queue_name)
|
|
|
|
print("All queues purged")
|
|
|
|
elif not options['queue_name']:
|
|
|
|
raise CommandError("Missing queue_name argument!")
|
|
|
|
else:
|
|
|
|
queue_name = options['queue_name']
|
2018-11-03 00:05:13 +01:00
|
|
|
if not (queue_name in get_active_worker_queues() or
|
dependencies: Remove WebSockets system for sending messages.
Zulip has had a small use of WebSockets (specifically, for the code
path of sending messages, via the webapp only) since ~2013. We
originally added this use of WebSockets in the hope that the latency
benefits of doing so would allow us to avoid implementing a markdown
local echo; they were not. Further, HTTP/2 may have eliminated the
latency difference we hoped to exploit by using WebSockets in any
case.
While we’d originally imagined using WebSockets for other endpoints,
there was never a good justification for moving more components to the
WebSockets system.
This WebSockets code path had a lot of downsides/complexity,
including:
* The messy hack involving constructing an emulated request object to
hook into doing Django requests.
* The `message_senders` queue processor system, which increases RAM
needs and must be provisioned independently from the rest of the
server).
* A duplicate check_send_receive_time Nagios test specific to
WebSockets.
* The requirement for users to have their firewalls/NATs allow
WebSocket connections, and a setting to disable them for networks
where WebSockets don’t work.
* Dependencies on the SockJS family of libraries, which has at times
been poorly maintained, and periodically throws random JavaScript
exceptions in our production environments without a deep enough
traceback to effectively investigate.
* A total of about 1600 lines of our code related to the feature.
* Increased load on the Tornado system, especially around a Zulip
server restart, and especially for large installations like
zulipchat.com, resulting in extra delay before messages can be sent
again.
As detailed in
https://github.com/zulip/zulip/pull/12862#issuecomment-536152397, it
appears that removing WebSockets moderately increases the time it
takes for the `send_message` API query to return from the server, but
does not significantly change the time between when a message is sent
and when it is received by clients. We don’t understand the reason
for that change (suggesting the possibility of a measurement error),
and even if it is a real change, we consider that potential small
latency regression to be acceptable.
If we later want WebSockets, we’ll likely want to just use Django
Channels.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-23 01:43:40 +02:00
|
|
|
queue_name.startswith("notify_tornado")):
|
2020-06-10 06:41:04 +02:00
|
|
|
raise CommandError(f"Unknown queue {queue_name}")
|
2017-06-05 07:47:03 +02:00
|
|
|
|
2020-06-10 06:41:04 +02:00
|
|
|
print(f"Purging queue {queue_name}")
|
2017-06-05 07:47:03 +02:00
|
|
|
purge_queue(queue_name)
|
|
|
|
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Done")
|