Skip to content

Commit

Permalink
Merge pull request #502 from telmobarros/master
Browse files Browse the repository at this point in the history
Add broker name in Schedule and enhanced Queued Tasks list display admin
  • Loading branch information
Koed00 committed Feb 11, 2021
2 parents 8d75fb9 + c838fa8 commit f322eed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions django_q/admin.py
Expand Up @@ -99,6 +99,8 @@ def get_queryset(self, request):
def has_add_permission(self, request):
"""Don't allow adds."""
return False

list_filter = ("key",)


admin.site.register(Schedule, ScheduleAdmin)
Expand Down
7 changes: 6 additions & 1 deletion django_q/cluster.py
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion docs/schedules.rst
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f322eed

Please sign in to comment.