mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-09 04:38:11 +08:00
Linting and hints
This commit is contained in:
+11
-9
@@ -1,13 +1,13 @@
|
||||
from datetime import timedelta
|
||||
from time import sleep
|
||||
|
||||
from django.utils import timezone
|
||||
from django import db
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from django_q.brokers import Broker
|
||||
from django_q.models import OrmQ
|
||||
from django_q.conf import Conf, logger
|
||||
from django_q.models import OrmQ
|
||||
|
||||
|
||||
def _timeout():
|
||||
@@ -16,8 +16,10 @@ def _timeout():
|
||||
|
||||
class ORM(Broker):
|
||||
@staticmethod
|
||||
def get_connection(list_key=Conf.PREFIX):
|
||||
if transaction.get_autocommit(using=Conf.ORM): # Only True when not in an atomic block
|
||||
def get_connection(list_key: str = Conf.PREFIX):
|
||||
if transaction.get_autocommit(
|
||||
using=Conf.ORM
|
||||
): # Only True when not in an atomic block
|
||||
# Make sure stale connections in the broker thread are explicitly
|
||||
# closed before attempting DB access.
|
||||
# logger.debug("Broker thread calling close_old_connections")
|
||||
@@ -26,14 +28,14 @@ class ORM(Broker):
|
||||
logger.debug("Broker in an atomic transaction")
|
||||
return OrmQ.objects.using(Conf.ORM)
|
||||
|
||||
def queue_size(self):
|
||||
def queue_size(self) -> int:
|
||||
return (
|
||||
self.get_connection()
|
||||
.filter(key=self.list_key, lock__lte=_timeout())
|
||||
.count()
|
||||
)
|
||||
|
||||
def lock_size(self):
|
||||
def lock_size(self) -> int:
|
||||
return (
|
||||
self.get_connection().filter(key=self.list_key, lock__gt=_timeout()).count()
|
||||
)
|
||||
@@ -41,10 +43,10 @@ class ORM(Broker):
|
||||
def purge_queue(self):
|
||||
return self.get_connection().filter(key=self.list_key).delete()
|
||||
|
||||
def ping(self):
|
||||
def ping(self) -> bool:
|
||||
return True
|
||||
|
||||
def info(self):
|
||||
def info(self) -> str:
|
||||
if not self._info:
|
||||
self._info = f"ORM {Conf.ORM}"
|
||||
return self._info
|
||||
@@ -60,7 +62,7 @@ class ORM(Broker):
|
||||
|
||||
def dequeue(self):
|
||||
tasks = self.get_connection().filter(key=self.list_key, lock__lt=_timeout())[
|
||||
0: Conf.BULK
|
||||
0 : Conf.BULK
|
||||
]
|
||||
if tasks:
|
||||
task_list = []
|
||||
|
||||
Reference in New Issue
Block a user