From 782b1de60d8d3bbeec3c1f5ffc6110c28577c404 Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:45:40 +0100 Subject: [PATCH] Allow different broker on chain (#156) --- django_q/tasks.py | 4 ++-- docs/chain.rst | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django_q/tasks.py b/django_q/tasks.py index 17bb204..92aa63f 100644 --- a/django_q/tasks.py +++ b/django_q/tasks.py @@ -569,10 +569,10 @@ class Chain: A sequential chain of tasks """ - def __init__(self, chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC): + def __init__(self, chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC, broker=None): self.chain = chain or [] self.group = group or "" - self.broker = get_broker() + self.broker = broker or get_broker() self.cached = cached self.sync = sync self.started = False diff --git a/docs/chain.rst b/docs/chain.rst index b372dca..34f7146 100644 --- a/docs/chain.rst +++ b/docs/chain.rst @@ -49,8 +49,9 @@ Reference :param str group: an optional group name. :param bool cached: run this against the cache backend :param bool sync: execute this inline instead of asynchronous + :param broker: an optional broker instance -.. py:class:: Chain(chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC) +.. py:class:: Chain(chain=None, group=None, cached=Conf.CACHED, sync=Conf.SYNC, broker=None) A sequential chain of tasks. Acts as a convenient wrapper for :func:`async_chain` You can pass the task chain at construction or you can append individual tasks before running them. @@ -59,6 +60,8 @@ Reference :param str group: an optional group name. :param bool cached: run this against the cache backend :param bool sync: execute this inline instead of asynchronous + :param bool sync: execute this inline instead of asynchronous + :param broker: an optional broker instance .. py:method:: append(func, *args, **kwargs)