Permalink
Browse files

Simplifying the name used to serialize a command and removing dynamic

import stuff
  • Loading branch information...
1 parent 4123ecf commit 5c9016f6c6d574ff9c88eccc6be72d83d15b8b19 @coleifer committed Jan 30, 2012
Showing with 8 additions and 33 deletions.
  1. +4 −15 huey/registry.py
  2. +3 −3 huey/tests/queue.py
  3. +1 −15 huey/tests/registry.py
View
@@ -12,12 +12,11 @@ class CommandRegistry(object):
_registry = {}
_periodic_commands = []
- _import_attempts = set()
message_template = '%(TASK_ID)s:%(CLASS)s:%(TIME)s:%(RETRIES)s:%(RETRY_DELAY)s:%(DATA)s'
def command_to_string(self, command):
- return '%s.%s' % (command.__module__, command.__name__)
+ return '%s' % (command.__name__)
def register(self, command_class):
klass_str = self.command_to_string(command_class)
@@ -33,14 +32,14 @@ def unregister(self, command_class):
klass_str = self.command_to_string(command_class)
if klass_str in self._registry:
- del(self._registry[str(command_class)])
+ del(self._registry[klass_str])
for command in self._periodic_commands:
if isinstance(command, command_class):
self._periodic_commands.remove(command)
- def __contains__(self, command_class):
- return str(command_class) in self._registry
+ def __contains__(self, klass_str):
+ return klass_str in self._registry
def get_message_for_command(self, command):
"""Convert a command object to a message for storage in the queue"""
@@ -56,16 +55,6 @@ def get_message_for_command(self, command):
def get_command_class(self, klass_str):
klass = self._registry.get(klass_str)
- if not klass and klass_str not in self._import_attempts:
- self._import_attempts.add(klass_str)
- module_name, attr = klass_str.rsplit('.', 1)
- try:
- module = __import__(module_name)
- except:
- pass
- else:
- return self.get_command_class(klass_str)
-
if not klass:
raise QueueException, '%s not found in CommandRegistry' % klass_str
View
@@ -67,9 +67,9 @@ def setUp(self):
state = {}
def test_registration(self):
- self.assertTrue('huey.tests.queue.queuecmd_add' in registry)
- self.assertTrue('huey.tests.queue.queuecmd_add_on_the_hour' in registry)
- self.assertTrue('huey.tests.queue.AddCommand' in registry)
+ self.assertTrue('queuecmd_add' in registry)
+ self.assertTrue('queuecmd_add_on_the_hour' in registry)
+ self.assertTrue('AddCommand' in registry)
def test_enqueue(self):
# sanity check
View
@@ -6,18 +6,4 @@
class HueyRegistryTestCase(unittest.TestCase):
- def test_get_command_class(self):
- klass_str = 'huey.tests.test_cmd.queuecmd_test_command_xxx'
-
- # ensure it has not been imported or seen yet
- self.assertFalse(klass_str in registry._registry)
-
- # this will import the module dynamically
- test_cmd = registry.get_command_class(klass_str)
- self.assertEqual(test_cmd(((1,), {})).execute(), 1)
-
- # this will raise a QueueException, even though the module is valid
- self.assertRaises(QueueException, registry.get_command_class, 'huey.tests.test_cmd.queuecmd_does_not_exist')
-
- # this will raise a QueueException after the import fails
- self.assertRaises(QueueException, registry.get_command_class, 'huey.does.not.exist')
+ pass

0 comments on commit 5c9016f

Please sign in to comment.