From cbe51f995cdbccdb032a03e5a84a4b7926d51a5d Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:44:37 +0200 Subject: [PATCH] Move timeout function from ORM broker into class to allow easy customization (#274) * move timeout function to class to allow customization * format * fix format --- django_q/brokers/orm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/django_q/brokers/orm.py b/django_q/brokers/orm.py index b8793f4..bb51f66 100644 --- a/django_q/brokers/orm.py +++ b/django_q/brokers/orm.py @@ -10,10 +10,6 @@ from django_q.conf import Conf, logger from django_q.models import OrmQ -def _timeout(): - return timezone.now() + timedelta(seconds=Conf.RETRY) - - class ORM(Broker): @staticmethod def get_connection(list_key: str = None): @@ -28,6 +24,9 @@ class ORM(Broker): logger.debug("Broker in an atomic transaction") return OrmQ.objects.using(Conf.ORM) + def timeout(self, task): + return timezone.now() + timedelta(seconds=Conf.RETRY) + def queue_size(self) -> int: return ( self.get_connection() @@ -75,7 +74,7 @@ class ORM(Broker): if ( self.get_connection() .filter(id=task.id, lock=task.lock) - .update(lock=_timeout()) + .update(lock=self.timeout(task)) ): task_list.append((task.pk, task.payload)) # else don't process, as another cluster has been faster than us on