mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 14:08:23 +00:00
Prepare process_queue to be used with supervisor's numprocs
(imported from commit 5a652b93f1e8b32b5ed89d622035161abaedfb11)
This commit is contained in:
@@ -9,24 +9,30 @@ import signal
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
args = "<queue name>"
|
args = "<queue name> [<worker number>]"
|
||||||
help = "Runs a queue processing worker"
|
help = "Runs a queue processing worker"
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
logger = logging.getLogger('process_queue')
|
logger = logging.getLogger('process_queue')
|
||||||
|
|
||||||
if len(args) != 1:
|
if len(args) not in (1, 2):
|
||||||
raise CommandError("Wrong number of arguments")
|
raise CommandError("Wrong number of arguments")
|
||||||
|
|
||||||
|
queue_name = args[0]
|
||||||
|
if len(args) > 1:
|
||||||
|
worker_num = int(args[1])
|
||||||
|
else:
|
||||||
|
worker_num = 0
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
def signal_handler(signal, frame):
|
||||||
logger.info("Disconnecting from queue")
|
logger.info("Worker %d disconnecting from queue %s" % (worker_num, queue_name))
|
||||||
worker.stop()
|
worker.stop()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, signal_handler)
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
logger.info("Connecting to queue")
|
logger.info("Worker %d connecting to queue %s" % (worker_num, queue_name))
|
||||||
worker = get_worker(args[0])
|
worker = get_worker(queue_name)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user