mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-10 21:40:56 +08:00
Linting and hints
This commit is contained in:
+12
-11
@@ -1,31 +1,32 @@
|
||||
from iron_mq import IronMQ, Queue
|
||||
from requests.exceptions import HTTPError
|
||||
from django_q.conf import Conf
|
||||
|
||||
from django_q.brokers import Broker
|
||||
from iron_mq import IronMQ
|
||||
from django_q.conf import Conf
|
||||
|
||||
|
||||
class IronMQBroker(Broker):
|
||||
def enqueue(self, task):
|
||||
return self.connection.post(task)['ids'][0]
|
||||
return self.connection.post(task)["ids"][0]
|
||||
|
||||
def dequeue(self):
|
||||
timeout = Conf.RETRY or None
|
||||
tasks = self.connection.get(timeout=timeout, wait=1, max=Conf.BULK)['messages']
|
||||
tasks = self.connection.get(timeout=timeout, wait=1, max=Conf.BULK)["messages"]
|
||||
if tasks:
|
||||
return [(t['id'], t['body']) for t in tasks]
|
||||
return [(t["id"], t["body"]) for t in tasks]
|
||||
|
||||
def ping(self):
|
||||
def ping(self) -> bool:
|
||||
return self.connection.name == self.list_key
|
||||
|
||||
def info(self):
|
||||
return 'IronMQ'
|
||||
def info(self) -> str:
|
||||
return "IronMQ"
|
||||
|
||||
def queue_size(self):
|
||||
return self.connection.size()
|
||||
|
||||
def delete_queue(self):
|
||||
try:
|
||||
return self.connection.delete_queue()['msg']
|
||||
return self.connection.delete_queue()["msg"]
|
||||
except HTTPError:
|
||||
return False
|
||||
|
||||
@@ -34,7 +35,7 @@ class IronMQBroker(Broker):
|
||||
|
||||
def delete(self, task_id):
|
||||
try:
|
||||
return self.connection.delete(task_id)['msg']
|
||||
return self.connection.delete(task_id)["msg"]
|
||||
except HTTPError:
|
||||
return False
|
||||
|
||||
@@ -45,6 +46,6 @@ class IronMQBroker(Broker):
|
||||
return self.delete(task_id)
|
||||
|
||||
@staticmethod
|
||||
def get_connection(list_key=Conf.PREFIX):
|
||||
def get_connection(list_key: str = Conf.PREFIX) -> Queue:
|
||||
ironmq = IronMQ(name=None, **Conf.IRON_MQ)
|
||||
return ironmq.queue(queue_name=list_key)
|
||||
|
||||
Reference in New Issue
Block a user