Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cleanup] Few cleanup commit for linting and migrations #447

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_q/brokers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django_q.conf import Conf


class Broker(object):
class Broker:
def __init__(self, list_key=Conf.PREFIX):
self.connection = self.get_connection(list_key)
self.list_key = list_key
Expand Down
1 change: 0 additions & 1 deletion django_q/brokers/aws_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def get_connection(list_key=Conf.PREFIX):
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)
8 changes: 4 additions & 4 deletions django_q/brokers/ironmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def enqueue(self, task):
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
Expand Down
2 changes: 1 addition & 1 deletion django_q/brokers/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def enqueue(self, task):

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 = []
Expand Down
10 changes: 2 additions & 8 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Future
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import ast

# Standard
Expand Down Expand Up @@ -36,7 +30,7 @@
from django_q.status import Stat, Status


class Cluster(object):
class Cluster:
def __init__(self, broker=None):
self.broker = broker or get_broker()
self.sentinel = None
Expand Down Expand Up @@ -120,7 +114,7 @@ def has_stopped(self):
return self.start_event is None and self.stop_event is None and self.sentinel


class Sentinel(object):
class Sentinel:
def __init__(
self,
stop_event,
Expand Down
4 changes: 2 additions & 2 deletions django_q/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
psutil = None


class Conf(object):
class Conf:
"""
Configuration class
"""
Expand Down Expand Up @@ -195,7 +195,7 @@ class Conf(object):


# Error Reporting Interface
class ErrorReporter(object):
class ErrorReporter:

# initialize with iterator of reporters (better name, targets?)
def __init__(self, reporters):
Expand Down
2 changes: 1 addition & 1 deletion django_q/humanhash.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'zulu')


class HumanHasher(object):
class HumanHasher:

"""
Transforms hex digests to human-readable strings.
Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import picklefield.fields
import django.utils.timezone
Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0002_auto_20150630_1624.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0003_auto_20150708_1326.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0004_auto_20150710_1043.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0005_auto_20150718_1506.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0006_auto_20150805_1817.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0007_ormq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0008_auto_20160224_1026.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
3 changes: 0 additions & 3 deletions django_q/migrations/0009_auto_20171009_0915.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
2 changes: 1 addition & 1 deletion django_q/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import multiprocessing.queues


class SharedCounter(object):
class SharedCounter:
""" A synchronized shared counter.

The locking done by multiprocessing.Value ensures that only a single
Expand Down
4 changes: 2 additions & 2 deletions django_q/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
BadSignature = signing.BadSignature


class SignedPackage(object):
class SignedPackage:

"""Wraps Django's signing module with custom Pickle serializer."""

Expand All @@ -31,7 +31,7 @@ def loads(obj):
serializer=PickleSerializer)


class PickleSerializer(object):
class PickleSerializer:

"""Simple wrapper around Pickle for signing.dumps and signing.loads."""

Expand Down
2 changes: 1 addition & 1 deletion django_q/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django_q.signing import SignedPackage, BadSignature


class Status(object):
class Status:
"""Cluster status base class."""

def __init__(self, pid, cluster_id):
Expand Down
9 changes: 4 additions & 5 deletions django_q/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
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
Expand Down Expand Up @@ -480,7 +479,7 @@ def async_chain(chain, group=None, cached=Conf.CACHED, sync=Conf.SYNC, broker=No
return group


class Iter(object):
class Iter:
"""
An async task with iterable arguments
"""
Expand Down Expand Up @@ -550,7 +549,7 @@ def length(self):
return len(self.args)


class Chain(object):
class Chain:
"""
A sequential chain of tasks
"""
Expand Down Expand Up @@ -634,7 +633,7 @@ def length(self):
return len(self.chain)


class AsyncTask(object):
class AsyncTask:
"""
an async task
"""
Expand Down
15 changes: 10 additions & 5 deletions django_q/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from django_q.queues import Queue


class WordClass(object):
class WordClass:
def __init__(self):
self.word_list = DEFAULT_WORDLIST

Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -434,10 +436,12 @@ def acknowledge(self, task_id):

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()
Expand All @@ -453,6 +457,7 @@ def acknowledge(self, task_id):
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
Expand Down
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,7 @@
import base64
import zlib

class DictImporter(object):
class DictImporter:
def __init__(self, sources):
self.sources = sources

Expand Down