Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Commit d9c0bd4

Browse files
committed
Merge pull request #142 from Affectiva/resque_compatibility
handle jobs queued by Ruby Resque with no module
2 parents 89811a7 + c100e3f commit d9c0bd4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pyres/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def safe_str_to_class(s):
9090
klass = lst[-1]
9191
mod_list = lst[:-1]
9292
module = ".".join(mod_list)
93+
94+
# ruby compatibility kludge: resque sends just a class name and
95+
# not a module name so if I use resque to queue a ruby class
96+
# called "Worker" then pyres will throw a "ValueError: Empty
97+
# module name" exception. To avoid that, if there's no module in
98+
# the json then we'll use the classname as a module name.
99+
if not module:
100+
module = klass
101+
93102
mod = my_import(module)
94103
if hasattr(mod, klass):
95104
return getattr(mod, klass)

tests/__init__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
import os
33
from pyres import ResQ, str_to_class
44

5+
class tests(object):
6+
queue = 'basic'
7+
8+
@staticmethod
9+
def perform(name):
10+
s = "name:%s" % name
11+
return s
12+
513
class Basic(object):
614
queue = 'basic'
715

@@ -111,7 +119,9 @@ def test_safe_str_to_class(self):
111119
assert safe_str_to_class('tests.Basic') == Basic
112120
self.assertRaises(ImportError, safe_str_to_class, 'test.Mine')
113121
self.assertRaises(ImportError, safe_str_to_class, 'tests.World')
114-
122+
# test that we'll use the class name as a module name if no
123+
# module name is provided (for Ruby compatibility)
124+
assert safe_str_to_class('tests') == tests
115125

116126
class PyResTests(unittest.TestCase):
117127
def setUp(self):

0 commit comments

Comments
 (0)