From 10df8351ff98bc1aa3a219f7b15a7a87b82ebc3f Mon Sep 17 00:00:00 2001 From: Telmo Barros Date: Sat, 6 Feb 2021 17:56:03 +0000 Subject: [PATCH 1/3] Queued tasks admin list page enhancement --- django_q/admin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django_q/admin.py b/django_q/admin.py index a7484ce..66c4d01 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -99,6 +99,9 @@ class QueueAdmin(admin.ModelAdmin): def has_add_permission(self, request): """Don't allow adds.""" return False + + list_filter = ("key", "func") + search_fields = ("name", "func") admin.site.register(Schedule, ScheduleAdmin) From 1d6d996fd0e461507458a797cd8f1f2055b2b80a Mon Sep 17 00:00:00 2001 From: Telmo Barros Date: Sat, 6 Feb 2021 18:52:17 +0000 Subject: [PATCH 2/3] enhanced admin ormq panel fix and schedules with broker_name --- django_q/admin.py | 3 +-- django_q/cluster.py | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/django_q/admin.py b/django_q/admin.py index 66c4d01..b4a12f3 100644 --- a/django_q/admin.py +++ b/django_q/admin.py @@ -100,8 +100,7 @@ class QueueAdmin(admin.ModelAdmin): """Don't allow adds.""" return False - list_filter = ("key", "func") - search_fields = ("name", "func") + list_filter = ("key",) admin.site.register(Schedule, ScheduleAdmin) diff --git a/django_q/cluster.py b/django_q/cluster.py index 5fc437e..d5532fa 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -633,7 +633,12 @@ def scheduler(broker: Broker = None): ) s.repeats += -1 # send it to the cluster - q_options["broker"] = broker + scheduled_broker = broker + try: + scheduled_broker = get_broker(q_options["broker_name"]) + except: # invalid broker_name or non existing broker with broker_name + pass + q_options["broker"] = scheduled_broker q_options["group"] = q_options.get("group", s.name or s.id) kwargs["q_options"] = q_options s.task = django_q.tasks.async_task(s.func, *args, **kwargs) From c838fa82e4a1142dac737daa3d05c866f28e1ee9 Mon Sep 17 00:00:00 2001 From: Telmo Barros Date: Thu, 11 Feb 2021 13:04:00 +0000 Subject: [PATCH 3/3] Add broker name in Schedule docs --- docs/schedules.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/schedules.rst b/docs/schedules.rst index 9d4e5fe..d0fe81d 100644 --- a/docs/schedules.rst +++ b/docs/schedules.rst @@ -28,10 +28,11 @@ You can manage them through the :ref:`admin_page` or directly from your code wit ) # In case you want to use q_options + # Specify the broker by using the property broker_name in q_options schedule('math.sqrt', 9, hook='hooks.print_result', - q_options={'timeout': 30}, + q_options={'timeout': 30, 'broker_name': 'broker_1'}, schedule_type=Schedule.HOURLY) # Run a schedule every 5 minutes, starting at 6 today @@ -117,6 +118,11 @@ Reference :param datetime next_run: Next or first scheduled execution datetime. :param dict q_options: options passed to async_task for this schedule :param kwargs: optional keyword arguments for the scheduled function. + + .. note:: + + q_options does not accept the 'broker' key with a broker instance but accepts a 'broker_name' key instead. This can be used to specify the broker connection name to assign the task. If a broker with the specified name does not exist or is not running at the moment of placing the task in queue it fallbacks to the random broker/queue that handled the schedule. + .. class:: Schedule