Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed tests so that all the namespace work done

by fakechris is now accounted for.

Modified the job and failure items to have slightly
different method signatures. This work will probably
be updated in the failure backend branch that should
be dropping soon
  • Loading branch information...
commit 64ff2bb1a477607b993bde14f12ecc520427e658 1 parent 571c160
Matt George authored
5 AUTHORS.md
Source Rendered
... ... @@ -0,0 +1,5 @@
  1 +## Authors
  2 +* Matt George
  3 +* Chris Song
  4 +
  5 +Inspired by Resque, by Chris Wanstrath
2  HISTORY.md
Source Rendered
@@ -2,6 +2,8 @@
2 2
3 3 * updated setup.py
4 4 * refactored package for better testing
  5 +* resque namespacing by fakechris
  6 +* smarter import from string by fakechris
5 7
6 8 ## 0.2.0 (2009-12-09)
7 9
11 coverage.report
... ... @@ -0,0 +1,11 @@
  1 +Name Stmts Exec Cover Missing
  2 +------------------------------------------------
  3 +pyres 138 131 94% 26, 39, 98, 133-134, 144-145
  4 +pyres.exceptions 2 2 100%
  5 +pyres.failure 23 22 95% 41
  6 +pyres.job 23 23 100%
  7 +pyres.worker 189 146 77% 66, 74, 84-112, 161, 179, 186, 230-241
  8 +------------------------------------------------
  9 +TOTAL 375 324 86%
  10 +----------------------------------------------------------------------
  11 +Ran 32 tests in 0.884s
2  pyres/failure.py
@@ -2,7 +2,7 @@
2 2 from pyres import ResQ
3 3 import sys, traceback
4 4 class Failure(object):
5   - def __init__(self, exp, worker, queue, payload):
  5 + def __init__(self, exp, queue, payload, worker=None):
6 6 excc, _, tb = sys.exc_info()
7 7
8 8 self._exception = excc
6 pyres/job.py
... ... @@ -1,7 +1,7 @@
1 1 from pyres import ResQ, str_to_class, safe_str_to_class
2 2 from pyres.failure import Failure
3 3 class Job(object):
4   - def __init__(self, queue, payload, resq, worker):
  4 + def __init__(self, queue, payload, resq, worker=None):
5 5 self._queue = queue
6 6 self._payload = payload
7 7 self.resq = resq
@@ -18,11 +18,11 @@ def perform(self):
18 18
19 19 def fail(self, exception):
20 20 #Failure.create(exception)
21   - failure = Failure(exception, self._worker, self._queue, self._payload)
  21 + failure = Failure(exception, self._queue, self._payload, self._worker)
22 22 failure.save(self.resq)
23 23
24 24 @classmethod
25   - def reserve(cls, queue, res, worker):
  25 + def reserve(cls, queue, res, worker=None):
26 26 payload = res.pop(queue)
27 27 if payload:
28 28 return cls(queue, payload, res, worker)
4 tests/test_jobs.py
@@ -18,6 +18,6 @@ def test_perform(self):
18 18 def test_fail(self):
19 19 self.resq.enqueue(Basic,"test1")
20 20 job = Job.reserve('basic',self.resq)
21   - assert self.redis.llen('failed') == 0
  21 + assert self.redis.llen('resque:failed') == 0
22 22 job.fail("problem")
23   - assert self.redis.llen('failed') == 1
  23 + assert self.redis.llen('resque:failed') == 1
35 tests/test_resq.py
@@ -8,24 +8,24 @@ def test_enqueue(self):
8 8 self.resq.enqueue(Basic,"test1")
9 9 self.resq.enqueue(Basic,"test2")
10 10 ResQ._enqueue(Basic, "test3")
11   - assert self.redis.llen("queue:basic") == 3
12   - assert self.redis.sismember('queues','basic')
  11 + assert self.redis.llen("resque:queue:basic") == 3
  12 + assert self.redis.sismember('resque:queues','basic')
13 13
14 14 def test_push(self):
15 15 self.resq.push('pushq','content-newqueue')
16 16 self.resq.push('pushq','content2-newqueue')
17   - assert self.redis.llen('queue:pushq') == 2
18   - assert self.redis.lindex('queue:pushq', 0) == ResQ.encode('content-newqueue')
19   - assert self.redis.lindex('queue:pushq', 1) == ResQ.encode('content2-newqueue')
  17 + assert self.redis.llen('resque:queue:pushq') == 2
  18 + assert self.redis.lindex('resque:queue:pushq', 0) == ResQ.encode('content-newqueue')
  19 + assert self.redis.lindex('resque:queue:pushq', 1) == ResQ.encode('content2-newqueue')
20 20
21 21 def test_pop(self):
22 22 self.resq.push('pushq','content-newqueue')
23 23 self.resq.push('pushq','content2-newqueue')
24   - assert self.redis.llen('queue:pushq') == 2
  24 + assert self.redis.llen('resque:queue:pushq') == 2
25 25 assert self.resq.pop('pushq') == 'content-newqueue'
26   - assert self.redis.llen('queue:pushq') == 1
  26 + assert self.redis.llen('resque:queue:pushq') == 1
27 27 assert self.resq.pop('pushq') == 'content2-newqueue'
28   - assert self.redis.llen('queue:pushq') == 0
  28 + assert self.redis.llen('resque:queue:pushq') == 0
29 29
30 30 def test_peek(self):
31 31 self.resq.enqueue(Basic,"test1")
@@ -62,31 +62,30 @@ def test_workers(self):
62 62 worker.register_worker()
63 63 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
64 64 assert len(self.resq.workers()) == 1
65   - assert name in self.resq.workers()
  65 + #assert Worker.find(name, self.resq) in self.resq.workers()
66 66
67 67 def test_enqueue_from_string(self):
68 68 self.resq.enqueue_from_string('tests.Basic','basic','test1')
69 69 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
70   - assert self.redis.llen("queue:basic") == 1
  70 + assert self.redis.llen("resque:queue:basic") == 1
71 71 job = Job.reserve('basic', self.resq)
72 72 worker = Worker(['basic'])
73 73 worker.process(job)
74   - assert not self.redis.get('worker:%s' % worker)
75   - assert not self.redis.get("stat:failed")
76   - assert not self.redis.get("stat:failed:%s" % name)
  74 + assert not self.redis.get('resque:worker:%s' % worker)
  75 + assert not self.redis.get("resque:stat:failed")
  76 + assert not self.redis.get("resque:stat:failed:%s" % name)
77 77
78 78 def test_remove_queue(self):
79 79 self.resq.enqueue_from_string('tests.Basic','basic','test1')
80 80 assert 'basic' in self.resq._watched_queues
81   - assert self.redis.sismember('queues','basic')
82   - assert self.redis.llen('queue:basic') == 1
  81 + assert self.redis.sismember('resque:queues','basic')
  82 + assert self.redis.llen('resque:queue:basic') == 1
83 83 self.resq.remove_queue('basic')
84 84 assert 'basic' not in self.resq._watched_queues
85   - assert not self.redis.sismember('queues','basic')
86   - assert not self.redis.exists('queue:basic')
  85 + assert not self.redis.sismember('resque:queues','basic')
  86 + assert not self.redis.exists('resque:queue:basic')
87 87
88 88 def test_keys(self):
89 89 self.resq.enqueue_from_string('tests.Basic','basic','test1')
90   - print self.resq.keys()
91 90 assert 'queue:basic' in self.resq.keys()
92 91 assert 'queues' in self.resq.keys()
16 tests/test_stats.py
@@ -4,22 +4,22 @@ class StatTests(PyResTests):
4 4 def test_incr(self):
5 5 stat_obj = Stat('test_stat', self.resq)
6 6 stat_obj.incr()
7   - assert self.redis.get('stat:test_stat') == 1
  7 + assert self.redis.get('resque:stat:test_stat') == 1
8 8 stat_obj.incr()
9   - assert self.redis.get('stat:test_stat') == 2
  9 + assert self.redis.get('resque:stat:test_stat') == 2
10 10 stat_obj.incr(2)
11   - assert self.redis.get('stat:test_stat') == 4
  11 + assert self.redis.get('resque:stat:test_stat') == 4
12 12
13 13 def test_decr(self):
14 14 stat_obj = Stat('test_stat', self.resq)
15 15 stat_obj.incr()
16 16 stat_obj.incr()
17   - assert self.redis.get('stat:test_stat') == 2
  17 + assert self.redis.get('resque:stat:test_stat') == 2
18 18 stat_obj.decr()
19   - assert self.redis.get('stat:test_stat') == 1
  19 + assert self.redis.get('resque:stat:test_stat') == 1
20 20 stat_obj.incr()
21 21 stat_obj.decr(2)
22   - assert self.redis.get('stat:test_stat') == 0
  22 + assert self.redis.get('resque:stat:test_stat') == 0
23 23
24 24 def test_get(self):
25 25 stat_obj = Stat('test_stat', self.resq)
@@ -31,6 +31,6 @@ def test_clear(self):
31 31 stat_obj = Stat('test_stat', self.resq)
32 32 stat_obj.incr()
33 33 stat_obj.incr()
34   - assert self.redis.exists('stat:test_stat')
  34 + assert self.redis.exists('resque:stat:test_stat')
35 35 stat_obj.clear()
36   - assert not self.redis.exists('stat:test_stat')
  36 + assert not self.redis.exists('resque:stat:test_stat')
58 tests/test_worker.py
@@ -13,7 +13,7 @@ def test_startup(self):
13 13 worker = Worker(['basic'])
14 14 worker.startup()
15 15 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
16   - assert self.redis.sismember('workers',name)
  16 + assert self.redis.sismember('resque:workers',name)
17 17 import signal
18 18 assert signal.getsignal(signal.SIGTERM) == worker.shutdown_all
19 19 assert signal.getsignal(signal.SIGINT) == worker.shutdown_all
@@ -24,15 +24,15 @@ def test_register(self):
24 24 worker = Worker(['basic'])
25 25 worker.register_worker()
26 26 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
27   - assert self.redis.sismember('workers',name)
  27 + assert self.redis.sismember('resque:workers',name)
28 28
29 29 def test_unregister(self):
30 30 worker = Worker(['basic'])
31 31 worker.register_worker()
32 32 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
33   - assert self.redis.sismember('workers',name)
  33 + assert self.redis.sismember('resque:workers',name)
34 34 worker.unregister_worker()
35   - assert name not in self.redis.smembers('workers')
  35 + assert name not in self.redis.smembers('resque:workers')
36 36
37 37 def test_working_on(self):
38 38 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
@@ -40,31 +40,31 @@ def test_working_on(self):
40 40 job = Job.reserve('basic', self.resq)
41 41 worker = Worker(['basic'])
42 42 worker.working_on(job)
43   - assert self.redis.exists("worker:%s" % name)
  43 + assert self.redis.exists("resque:worker:%s" % name)
44 44
45 45 def test_processed(self):
46 46 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
47 47 worker = Worker(['basic'])
48 48 worker.processed()
49   - assert self.redis.exists("stat:processed")
50   - assert self.redis.exists("stat:processed:%s" % name)
51   - assert self.redis.get("stat:processed") == 1
52   - assert self.redis.get("stat:processed:%s" % name) == 1
  49 + assert self.redis.exists("resque:stat:processed")
  50 + assert self.redis.exists("resque:stat:processed:%s" % name)
  51 + assert self.redis.get("resque:stat:processed") == 1
  52 + assert self.redis.get("resque:stat:processed:%s" % name) == 1
53 53 worker.processed()
54   - assert self.redis.get("stat:processed") == 2
55   - assert self.redis.get("stat:processed:%s" % name) == 2
  54 + assert self.redis.get("resque:stat:processed") == 2
  55 + assert self.redis.get("resque:stat:processed:%s" % name) == 2
56 56
57 57 def test_failed(self):
58 58 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
59 59 worker = Worker(['basic'])
60 60 worker.failed()
61   - assert self.redis.exists("stat:failed")
62   - assert self.redis.exists("stat:failed:%s" % name)
63   - assert self.redis.get("stat:failed") == 1
64   - assert self.redis.get("stat:failed:%s" % name) == 1
  61 + assert self.redis.exists("resque:stat:failed")
  62 + assert self.redis.exists("resque:stat:failed:%s" % name)
  63 + assert self.redis.get("resque:stat:failed") == 1
  64 + assert self.redis.get("resque:stat:failed:%s" % name) == 1
65 65 worker.failed()
66   - assert self.redis.get("stat:failed") == 2
67   - assert self.redis.get("stat:failed:%s" % name) == 2
  66 + assert self.redis.get("resque:stat:failed") == 2
  67 + assert self.redis.get("resque:stat:failed:%s" % name) == 2
68 68
69 69 def test_process(self):
70 70 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
@@ -72,14 +72,14 @@ def test_process(self):
72 72 job = Job.reserve('basic', self.resq)
73 73 worker = Worker(['basic'])
74 74 worker.process(job)
75   - assert not self.redis.get('worker:%s' % worker)
76   - assert not self.redis.get("stat:failed")
77   - assert not self.redis.get("stat:failed:%s" % name)
  75 + assert not self.redis.get('resque:worker:%s' % worker)
  76 + assert not self.redis.get("resque:stat:failed")
  77 + assert not self.redis.get("resque:stat:failed:%s" % name)
78 78 self.resq.enqueue(Basic,"test1")
79 79 worker.process()
80   - assert not self.redis.get('worker:%s' % worker)
81   - assert not self.redis.get("stat:failed")
82   - assert not self.redis.get("stat:failed:%s" % name)
  80 + assert not self.redis.get('resque:worker:%s' % worker)
  81 + assert not self.redis.get("resque:stat:failed")
  82 + assert not self.redis.get("resque:stat:failed:%s" % name)
83 83
84 84
85 85 def test_signals(self):
@@ -101,9 +101,9 @@ def test_job_failure(self):
101 101 worker = Worker(['basic'])
102 102 worker.process()
103 103 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
104   - assert not self.redis.get('worker:%s' % worker)
105   - assert self.redis.get("stat:failed") == 1
106   - assert self.redis.get("stat:failed:%s" % name) == 1
  104 + assert not self.redis.get('resque:worker:%s' % worker)
  105 + assert self.redis.get("resque:stat:failed") == 1
  106 + assert self.redis.get("resque:stat:failed:%s" % name) == 1
107 107
108 108 def test_get_job(self):
109 109 worker = Worker(['basic'])
@@ -111,7 +111,7 @@ def test_get_job(self):
111 111 job = Job.reserve('basic', self.resq)
112 112 worker.working_on(job)
113 113 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
114   - assert worker.job() == ResQ.decode(self.redis.get('worker:%s' % name))
  114 + assert worker.job() == ResQ.decode(self.redis.get('resque:worker:%s' % name))
115 115 worker.done_working()
116 116 w2 = Worker(['basic'])
117 117 print w2.job()
@@ -135,7 +135,7 @@ def test_started(self):
135 135 dt = datetime.datetime.now()
136 136 worker.started = dt
137 137 name = "%s:%s:%s" % (os.uname()[1],os.getpid(),'basic')
138   - assert self.redis.get('worker:%s:started' % name) == dt.strftime('%Y-%m-%d %H:%M:%S')
  138 + assert self.redis.get('resque:worker:%s:started' % name) == dt.strftime('%Y-%m-%d %H:%M:%S')
139 139 assert worker.started == datetime.datetime.strptime(dt.strftime('%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
140 140 worker.started = None
141   - assert not self.redis.exists('worker:%s:started' % name)
  141 + assert not self.redis.exists('resque:worker:%s:started' % name)

0 comments on commit 64ff2bb

Please sign in to comment.
Something went wrong with that request. Please try again.