Move timeout function from ORM broker into class to allow easy customization (#274)

* move timeout function to class to allow customization

* format

* fix format
This commit is contained in:
Stan Triepels
2025-04-23 15:44:37 +02:00
committed by GitHub
parent 0090a6f411
commit cbe51f995c

View File

@@ -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