mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-10 00:50:56 +08:00
Replaces format with f-strings
This commit is contained in:
+23
-21
@@ -6,43 +6,45 @@ from django_q.conf import Conf
|
||||
|
||||
class Disque(Broker):
|
||||
def enqueue(self, task):
|
||||
retry = Conf.RETRY if Conf.RETRY > 0 else '{} REPLICATE 1'.format(Conf.RETRY)
|
||||
retry = Conf.RETRY if Conf.RETRY > 0 else f"{Conf.RETRY} REPLICATE 1"
|
||||
return self.connection.execute_command(
|
||||
'ADDJOB {} {} 500 RETRY {}'.format(self.list_key, task, retry)).decode()
|
||||
f"ADDJOB {self.list_key} {task} 500 RETRY {retry}"
|
||||
).decode()
|
||||
|
||||
def dequeue(self):
|
||||
tasks = self.connection.execute_command(
|
||||
'GETJOB COUNT {} TIMEOUT 1000 FROM {}'.format(Conf.BULK, self.list_key))
|
||||
if tasks:
|
||||
return [(t[1].decode(), t[2].decode()) for t in tasks]
|
||||
tasks = self.connection.execute_command(
|
||||
f"GETJOB COUNT {Conf.BULK} TIMEOUT 1000 FROM {self.list_key}"
|
||||
)
|
||||
if tasks:
|
||||
return [(t[1].decode(), t[2].decode()) for t in tasks]
|
||||
|
||||
def queue_size(self):
|
||||
return self.connection.execute_command('QLEN {}'.format(self.list_key))
|
||||
return self.connection.execute_command(f"QLEN {self.list_key}")
|
||||
|
||||
def acknowledge(self, task_id):
|
||||
command = 'FASTACK' if Conf.DISQUE_FASTACK else 'ACKJOB'
|
||||
return self.connection.execute_command('{} {}'.format(command,task_id))
|
||||
command = "FASTACK" if Conf.DISQUE_FASTACK else "ACKJOB"
|
||||
return self.connection.execute_command(f"{command} {task_id}")
|
||||
|
||||
def ping(self):
|
||||
return self.connection.execute_command('HELLO')[0] > 0
|
||||
return self.connection.execute_command("HELLO")[0] > 0
|
||||
|
||||
def delete(self, task_id):
|
||||
return self.connection.execute_command('DELJOB {}'.format(task_id))
|
||||
return self.connection.execute_command(f"DELJOB {task_id}")
|
||||
|
||||
def fail(self, task_id):
|
||||
return self.delete(task_id)
|
||||
|
||||
def delete_queue(self):
|
||||
jobs = self.connection.execute_command('JSCAN QUEUE {}'.format(self.list_key))[1]
|
||||
jobs = self.connection.execute_command(f"JSCAN QUEUE {self.list_key}")[1]
|
||||
if jobs:
|
||||
job_ids = ' '.join(jid.decode() for jid in jobs)
|
||||
self.connection.execute_command('DELJOB {}'.format(job_ids))
|
||||
job_ids = " ".join(jid.decode() for jid in jobs)
|
||||
self.connection.execute_command(f"DELJOB {job_ids}")
|
||||
return len(jobs)
|
||||
|
||||
def info(self):
|
||||
if not self._info:
|
||||
info = self.connection.info('server')
|
||||
self._info= 'Disque {}'.format(info['disque_version'])
|
||||
info = self.connection.info("server")
|
||||
self._info = f'Disque {info["disque_version"]}'
|
||||
return self._info
|
||||
|
||||
@staticmethod
|
||||
@@ -51,15 +53,15 @@ class Disque(Broker):
|
||||
random.shuffle(Conf.DISQUE_NODES)
|
||||
# find one that works
|
||||
for node in Conf.DISQUE_NODES:
|
||||
host, port = node.split(':')
|
||||
kwargs = {'host': host, 'port': port}
|
||||
host, port = node.split(":")
|
||||
kwargs = {"host": host, "port": port}
|
||||
if Conf.DISQUE_AUTH:
|
||||
kwargs['password'] = Conf.DISQUE_AUTH
|
||||
kwargs["password"] = Conf.DISQUE_AUTH
|
||||
redis_client = redis.Redis(**kwargs)
|
||||
redis_client.decode_responses = True
|
||||
try:
|
||||
redis_client.execute_command('HELLO')
|
||||
redis_client.execute_command("HELLO")
|
||||
return redis_client
|
||||
except redis.exceptions.ConnectionError:
|
||||
continue
|
||||
raise redis.exceptions.ConnectionError('Could not connect to any Disque nodes')
|
||||
raise redis.exceptions.ConnectionError("Could not connect to any Disque nodes")
|
||||
|
||||
Reference in New Issue
Block a user