diff --git a/django_q/brokers/aws_sqs.py b/django_q/brokers/aws_sqs.py index d33800f..535259a 100644 --- a/django_q/brokers/aws_sqs.py +++ b/django_q/brokers/aws_sqs.py @@ -57,7 +57,6 @@ class Sqs(Broker): del(config['aws_region']) return Session(**config) - def get_queue(self): self.sqs = self.connection.resource('sqs') return self.sqs.create_queue(QueueName=self.list_key) diff --git a/django_q/brokers/ironmq.py b/django_q/brokers/ironmq.py index f0b0725..bf14dd8 100644 --- a/django_q/brokers/ironmq.py +++ b/django_q/brokers/ironmq.py @@ -9,10 +9,10 @@ class IronMQBroker(Broker): 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'] - if tasks: - return [(t['id'], t['body']) for t in tasks] + timeout = Conf.RETRY or None + tasks = self.connection.get(timeout=timeout, wait=1, max=Conf.BULK)['messages'] + if tasks: + return [(t['id'], t['body']) for t in tasks] def ping(self): return self.connection.name == self.list_key diff --git a/django_q/brokers/orm.py b/django_q/brokers/orm.py index 008503a..da5b289 100644 --- a/django_q/brokers/orm.py +++ b/django_q/brokers/orm.py @@ -60,7 +60,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 = [] diff --git a/django_q/tasks.py b/django_q/tasks.py index 1d9780a..c27eb8b 100644 --- a/django_q/tasks.py +++ b/django_q/tasks.py @@ -7,9 +7,8 @@ from django.db import IntegrityError from django.utils import timezone from multiprocessing import Value -from django_q.brokers import get_broker - # local +from django_q.brokers import get_broker from django_q.conf import Conf, logger from django_q.humanhash import uuid from django_q.models import Schedule, Task diff --git a/django_q/tests/test_cluster.py b/django_q/tests/test_cluster.py index 97d320a..9093036 100644 --- a/django_q/tests/test_cluster.py +++ b/django_q/tests/test_cluster.py @@ -45,6 +45,7 @@ def test_sync(broker): task = async_task('django_q.tests.tasks.count_letters', DEFAULT_WORDLIST, broker=broker, sync=True) assert result(task) == 1506 + @pytest.mark.django_db def test_sync_raise_exception(broker): with pytest.raises(TaskError): @@ -401,6 +402,7 @@ def test_update_failed(broker): assert saved_task.success is True assert saved_task.result == 'result' + @pytest.mark.django_db def test_acknowledge_failure_override(): class VerifyAckMockBroker(Broker): @@ -434,10 +436,12 @@ def test_acknowledge_failure_override(): tag = uuid() task_success_ack = task_fail_ack.copy() - task_success_ack.update({'id': tag[1], - 'name': tag[0], - 'ack_id': 'test_success_ack_id', - 'success': True,}) + task_success_ack.update({ + 'id': tag[1], + 'name': tag[0], + 'ack_id': 'test_success_ack_id', + 'success': True, + }) del task_success_ack['ack_failure'] result_queue = Queue() @@ -453,6 +457,7 @@ def test_acknowledge_failure_override(): assert broker.acknowledgements.get('test_fail_no_ack_id') is None assert broker.acknowledgements.get('test_success_ack_id') == 1 + @pytest.mark.django_db def assert_result(task): assert task is not None