Fix PEP8 complaints.

main
Vincent Driessen 11 years ago
parent 38ec259b6e
commit ab9e6b852e

@ -21,17 +21,17 @@ else:
"""Class decorator that fills in missing ordering methods""" """Class decorator that fills in missing ordering methods"""
convert = { convert = {
'__lt__': [('__gt__', lambda self, other: other < self), '__lt__': [('__gt__', lambda self, other: other < self),
('__le__', lambda self, other: not other < self), ('__le__', lambda self, other: not other < self),
('__ge__', lambda self, other: not self < other)], ('__ge__', lambda self, other: not self < other)],
'__le__': [('__ge__', lambda self, other: other <= self), '__le__': [('__ge__', lambda self, other: other <= self),
('__lt__', lambda self, other: not other <= self), ('__lt__', lambda self, other: not other <= self),
('__gt__', lambda self, other: not self <= other)], ('__gt__', lambda self, other: not self <= other)],
'__gt__': [('__lt__', lambda self, other: other > self), '__gt__': [('__lt__', lambda self, other: other > self),
('__ge__', lambda self, other: not other > self), ('__ge__', lambda self, other: not other > self),
('__le__', lambda self, other: not self > other)], ('__le__', lambda self, other: not self > other)],
'__ge__': [('__le__', lambda self, other: other >= self), '__ge__': [('__le__', lambda self, other: other >= self),
('__gt__', lambda self, other: not other >= self), ('__gt__', lambda self, other: not other >= self),
('__lt__', lambda self, other: not self >= other)] ('__lt__', lambda self, other: not self >= other)]
} }
roots = set(dir(cls)) & set(convert) roots = set(dir(cls)) & set(convert)
if not roots: if not roots:

@ -9,13 +9,13 @@ def register_sentry(client, worker):
""" """
def send_to_sentry(job, *exc_info): def send_to_sentry(job, *exc_info):
client.captureException( client.captureException(
exc_info=exc_info, exc_info=exc_info,
extra={ extra={
'job_id': job.id, 'job_id': job.id,
'func': job.func_name, 'func': job.func_name,
'args': job.args, 'args': job.args,
'kwargs': job.kwargs, 'kwargs': job.kwargs,
'description': job.description, 'description': job.description,
}) })
worker.push_exc_handler(send_to_sentry) worker.push_exc_handler(send_to_sentry)

@ -4,15 +4,18 @@ from __future__ import (absolute_import, division, print_function,
import inspect import inspect
from uuid import uuid4 from uuid import uuid4
from rq.compat import as_text, decode_redis_hash, string_types, text_type
from .connections import resolve_connection
from .exceptions import NoSuchJobError, UnpickleError
from .local import LocalStack
from .utils import import_attribute, utcformat, utcnow, utcparse
try: try:
from cPickle import loads, dumps, UnpicklingError from cPickle import loads, dumps, UnpicklingError
except ImportError: # noqa except ImportError: # noqa
from pickle import loads, dumps, UnpicklingError # noqa from pickle import loads, dumps, UnpicklingError # noqa
from .local import LocalStack
from .connections import resolve_connection
from .exceptions import UnpickleError, NoSuchJobError
from .utils import import_attribute, utcnow, utcformat, utcparse
from rq.compat import text_type, decode_redis_hash, as_text, string_types
def enum(name, *sequential, **named): def enum(name, *sequential, **named):

@ -28,7 +28,7 @@ def setup_loghandlers(level=None):
"handlers": { "handlers": {
"console": { "console": {
"level": "DEBUG", "level": "DEBUG",
#"class": "logging.StreamHandler", # "class": "logging.StreamHandler",
"class": "rq.utils.ColorizingStreamHandler", "class": "rq.utils.ColorizingStreamHandler",
"formatter": "console", "formatter": "console",
"exclude": ["%(asctime)s"], "exclude": ["%(asctime)s"],

@ -148,12 +148,10 @@ class Queue(object):
if Job.exists(job_id, self.connection): if Job.exists(job_id, self.connection):
self.connection.rpush(self.key, job_id) self.connection.rpush(self.key, job_id)
def push_job_id(self, job_id):
def push_job_id(self, job_id): # noqa
"""Pushes a job ID on the corresponding Redis queue.""" """Pushes a job ID on the corresponding Redis queue."""
self.connection.rpush(self.key, job_id) self.connection.rpush(self.key, job_id)
def enqueue_call(self, func, args=None, kwargs=None, timeout=None, def enqueue_call(self, func, args=None, kwargs=None, timeout=None,
result_ttl=None, description=None, depends_on=None): result_ttl=None, description=None, depends_on=None):
"""Creates a job to represent the delayed function call and enqueues """Creates a job to represent the delayed function call and enqueues
@ -347,7 +345,6 @@ class Queue(object):
raise e raise e
return job, queue return job, queue
# Total ordering defition (the rest of the required Python methods are # Total ordering defition (the rest of the required Python methods are
# auto-generated by the @total_ordering decorator) # auto-generated by the @total_ordering decorator)
def __eq__(self, other): # noqa def __eq__(self, other): # noqa

@ -14,6 +14,7 @@ def parse_args():
opts, args = parser.parse_args() opts, args = parser.parse_args()
return (opts, args, parser) return (opts, args, parser)
def main(): def main():
import sys import sys
sys.path.insert(0, '.') sys.path.insert(0, '.')
@ -25,12 +26,12 @@ def main():
queues = ('default', 'high', 'low') queues = ('default', 'high', 'low')
sample_calls = [ sample_calls = [
(dummy.do_nothing, [], {}), (dummy.do_nothing, [], {}),
(dummy.sleep, [1], {}), (dummy.sleep, [1], {}),
(dummy.fib, [8], {}), # normal result (dummy.fib, [8], {}), # normal result
(dummy.fib, [24], {}), # takes pretty long (dummy.fib, [24], {}), # takes pretty long
(dummy.div_by_zero, [], {}), # 5 / 0 => div by zero exc (dummy.div_by_zero, [], {}), # 5 / 0 => div by zero exc
(dummy.random_failure, [], {}), # simulate random failure (handy for requeue testing) (dummy.random_failure, [], {}), # simulate random failure (handy for requeue testing)
] ]
for i in range(opts.count): for i in range(opts.count):
@ -40,28 +41,27 @@ def main():
q = Queue(random.choice(queues)) q = Queue(random.choice(queues))
q.enqueue(f, *args, **kwargs) q.enqueue(f, *args, **kwargs)
#q = Queue('foo') # q = Queue('foo')
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(sleep, 3) # q.enqueue(sleep, 3)
#q = Queue('bar') # q = Queue('bar')
#q.enqueue(yield_stuff) # q.enqueue(yield_stuff)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
#q.enqueue(do_nothing) # q.enqueue(do_nothing)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -111,7 +111,7 @@ def show_workers(args):
queues = dict([(q, []) for q in qs]) queues = dict([(q, []) for q in qs])
for w in ws: for w in ws:
for q in w.queues: for q in w.queues:
if not q in queues: if q not in queues:
continue continue
queues[q].append(w) queues[q].append(w)

@ -68,7 +68,6 @@ class Worker(object):
redis_workers_keys = 'rq:workers' redis_workers_keys = 'rq:workers'
death_penalty_class = UnixSignalDeathPenalty death_penalty_class = UnixSignalDeathPenalty
@classmethod @classmethod
def all(cls, connection=None): def all(cls, connection=None):
"""Returns an iterable of all Workers. """Returns an iterable of all Workers.
@ -140,8 +139,7 @@ class Worker(object):
if exc_handler is not None: if exc_handler is not None:
self.push_exc_handler(exc_handler) self.push_exc_handler(exc_handler)
def validate_queues(self):
def validate_queues(self): # noqa
"""Sanity check for the given queues.""" """Sanity check for the given queues."""
if not iterable(self.queues): if not iterable(self.queues):
raise ValueError('Argument queues not iterable.') raise ValueError('Argument queues not iterable.')
@ -157,8 +155,7 @@ class Worker(object):
"""Returns the Redis keys representing this worker's queues.""" """Returns the Redis keys representing this worker's queues."""
return map(lambda q: q.key, self.queues) return map(lambda q: q.key, self.queues)
@property
@property # noqa
def name(self): def name(self):
"""Returns the name of the worker, under which it is registered to the """Returns the name of the worker, under which it is registered to the
monitoring system. monitoring system.
@ -201,8 +198,7 @@ class Worker(object):
""" """
setprocname('rq: %s' % (message,)) setprocname('rq: %s' % (message,))
def register_birth(self):
def register_birth(self): # noqa
"""Registers its own birth.""" """Registers its own birth."""
self.log.debug('Registering birth of worker %s' % (self.name,)) self.log.debug('Registering birth of worker %s' % (self.name,))
if self.connection.exists(self.key) and \ if self.connection.exists(self.key) and \
@ -326,8 +322,7 @@ class Worker(object):
signal.signal(signal.SIGINT, request_stop) signal.signal(signal.SIGINT, request_stop)
signal.signal(signal.SIGTERM, request_stop) signal.signal(signal.SIGTERM, request_stop)
def work(self, burst=False):
def work(self, burst=False): # noqa
"""Starts the work loop. """Starts the work loop.
Pops and performs all jobs on the current list of queues. When all Pops and performs all jobs on the current list of queues. When all

@ -79,5 +79,5 @@ class RQTestCase(unittest.TestCase):
# Pop the connection to Redis # Pop the connection to Redis
testconn = pop_connection() testconn = pop_connection()
assert testconn == cls.testconn, 'Wow, something really nasty ' \ assert testconn == cls.testconn, \
'happened to the Redis connection stack. Check your setup.' 'Wow, something really nasty happened to the Redis connection stack. Check your setup.'

@ -7,4 +7,3 @@ from datetime import timedelta
def strip_microseconds(date): def strip_microseconds(date):
return date - timedelta(microseconds=date.microsecond) return date - timedelta(microseconds=date.microsecond)

@ -44,7 +44,7 @@ class TestDecorator(RQTestCase):
"""Ensure that passing in result_ttl to the decorator sets the """Ensure that passing in result_ttl to the decorator sets the
result_ttl on the job result_ttl on the job
""" """
#Ensure default # Ensure default
result = decorated_job.delay(1, 2) result = decorated_job.delay(1, 2)
self.assertEqual(result.result_ttl, DEFAULT_RESULT_TTL) self.assertEqual(result.result_ttl, DEFAULT_RESULT_TTL)

@ -23,8 +23,7 @@ class TestQueue(RQTestCase):
q = Queue() q = Queue()
self.assertEquals(q.name, 'default') self.assertEquals(q.name, 'default')
def test_equality(self):
def test_equality(self): # noqa
"""Mathematical equality of queues.""" """Mathematical equality of queues."""
q1 = Queue('foo') q1 = Queue('foo')
q2 = Queue('foo') q2 = Queue('foo')
@ -35,8 +34,7 @@ class TestQueue(RQTestCase):
self.assertNotEquals(q1, q3) self.assertNotEquals(q1, q3)
self.assertNotEquals(q2, q3) self.assertNotEquals(q2, q3)
def test_empty_queue(self):
def test_empty_queue(self): # noqa
"""Emptying queues.""" """Emptying queues."""
q = Queue('example') q = Queue('example')
@ -109,8 +107,7 @@ class TestQueue(RQTestCase):
self.assertEquals(q.count, 2) self.assertEquals(q.count, 2)
def test_enqueue(self):
def test_enqueue(self): # noqa
"""Enqueueing job onto queues.""" """Enqueueing job onto queues."""
q = Queue() q = Queue()
self.assertEquals(q.is_empty(), True) self.assertEquals(q.is_empty(), True)
@ -142,8 +139,7 @@ class TestQueue(RQTestCase):
self.assertEquals(job.origin, q.name) self.assertEquals(job.origin, q.name)
self.assertIsNotNone(job.enqueued_at) self.assertIsNotNone(job.enqueued_at)
def test_pop_job_id(self):
def test_pop_job_id(self): # noqa
"""Popping job IDs from queues.""" """Popping job IDs from queues."""
# Set up # Set up
q = Queue() q = Queue()
@ -292,7 +288,6 @@ class TestQueue(RQTestCase):
((1,), {'timeout': 1, 'result_ttl': 1}) ((1,), {'timeout': 1, 'result_ttl': 1})
) )
def test_all_queues(self): def test_all_queues(self):
"""All queues""" """All queues"""
q1 = Queue('first-queue') q1 = Queue('first-queue')

@ -26,16 +26,16 @@ class TestWorker(RQTestCase):
fooq, barq = Queue('foo'), Queue('bar') fooq, barq = Queue('foo'), Queue('bar')
w = Worker([fooq, barq]) w = Worker([fooq, barq])
self.assertEquals(w.work(burst=True), False, self.assertEquals(w.work(burst=True), False,
'Did not expect any work on the queue.') 'Did not expect any work on the queue.')
fooq.enqueue(say_hello, name='Frank') fooq.enqueue(say_hello, name='Frank')
self.assertEquals(w.work(burst=True), True, self.assertEquals(w.work(burst=True), True,
'Expected at least some work done.') 'Expected at least some work done.')
def test_worker_ttl(self): def test_worker_ttl(self):
"""Worker ttl.""" """Worker ttl."""
w = Worker([]) w = Worker([])
w.register_birth() # ugly: our test should only call public APIs w.register_birth() # ugly: our test should only call public APIs
[worker_key] = self.testconn.smembers(Worker.redis_workers_keys) [worker_key] = self.testconn.smembers(Worker.redis_workers_keys)
self.assertIsNotNone(self.testconn.ttl(worker_key)) self.assertIsNotNone(self.testconn.ttl(worker_key))
w.register_death() w.register_death()
@ -46,7 +46,7 @@ class TestWorker(RQTestCase):
w = Worker([q]) w = Worker([q])
job = q.enqueue('tests.fixtures.say_hello', name='Frank') job = q.enqueue('tests.fixtures.say_hello', name='Frank')
self.assertEquals(w.work(burst=True), True, self.assertEquals(w.work(burst=True), True,
'Expected at least some work done.') 'Expected at least some work done.')
self.assertEquals(job.result, 'Hi there, Frank!') self.assertEquals(job.result, 'Hi there, Frank!')
def test_work_is_unreadable(self): def test_work_is_unreadable(self):
@ -175,10 +175,9 @@ class TestWorker(RQTestCase):
w = Worker([q]) w = Worker([q])
# Put it on the queue with a timeout value # Put it on the queue with a timeout value
res = q.enqueue( res = q.enqueue(create_file_after_timeout,
create_file_after_timeout, args=(sentinel_file, 4),
args=(sentinel_file, 4), timeout=1)
timeout=1)
try: try:
os.unlink(sentinel_file) os.unlink(sentinel_file)

Loading…
Cancel
Save