mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-15 13:37:56 +08:00
* Support for multi-queue, multi-cluster configuration. API changes include: * Adding `cluster` to async_task() parameters and Task model * Adding argument --name to qcluster command * Necessary adjustments to Conf and Broker classes * Some admin improvements * Add settings.Q_CLUSTER['ALT_CLUSTERS']: q_cluster config overrides for alternative clusters; Add Conf.CLUSTER_NAME: separate usage from Conf.PREFIX; QueueAdmin/OrmQ detail page enhanced: now displaying args/kwargs/q_options instead of encrypted payload. * if `cluster` argument is not set (the default), async_task() and schedule() will be handled by the default cluster; Documentation update. * Text cleanup * Documentation update. * Fix TIMEOUT setting in Windows for non-default cluster --------- Co-authored-by: Stan Triepels <1939656+GDay@users.noreply.github.com>
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from django.core.management.base import BaseCommand
|
|
from django.utils.translation import gettext as _
|
|
|
|
from django_q.cluster import Cluster
|
|
import os
|
|
|
|
|
|
class Command(BaseCommand):
|
|
# Translators: help text for qcluster management command
|
|
help = _("Starts a Django Q Cluster.")
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
"--run-once",
|
|
action="store_true",
|
|
dest="run_once",
|
|
default=False,
|
|
help="Run once and then stop.",
|
|
)
|
|
parser.add_argument(
|
|
"-n",
|
|
"--name",
|
|
dest="cluster_name",
|
|
default=None,
|
|
help="Set alternative cluster name instead of the name in Q_CLUSTER settings (for multi-queue setup). "
|
|
"On Linux you should set name through `Q_CLUSTER_NAME=cluster_name python manage.py qcluster` instead."
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
# Set alternative cluster_name before creating the cluster (cluster_name is broker's queue_name, too)
|
|
cluster_name = options.get("cluster_name")
|
|
if cluster_name:
|
|
os.environ["Q_CLUSTER_NAME"] = cluster_name
|
|
|
|
q = Cluster()
|
|
q.start()
|
|
if options.get("run_once", False):
|
|
q.stop()
|