diff --git a/pyres/__init__.py b/pyres/__init__.py index 011cd88..a38049d 100644 --- a/pyres/__init__.py +++ b/pyres/__init__.py @@ -86,7 +86,14 @@ def my_import(name): def safe_str_to_class(s): """Helper function to map string class names to module classes.""" - lst = s.split(".") + # ruby compatibility kludge: ruby uses "::" to separate modules + # from classes, while python uses "." so we'll sniff the string + # for "::" and if it's there then we're probably handling a job + # that was queued by ruby + if "::" in s: + lst = s.split("::") + else: + lst = s.split(".") klass = lst[-1] mod_list = lst[:-1] module = ".".join(mod_list) diff --git a/pyres/horde.py b/pyres/horde.py index b41b7a4..d1b6d36 100644 --- a/pyres/horde.py +++ b/pyres/horde.py @@ -109,7 +109,7 @@ def working_on(self, job): self.logger.debug('marking as working on') data = { 'queue': job._queue, - 'run_at': int(time.mktime(datetime.datetime.now().timetuple())), + 'run_at': datetime.datetime.utcnow().isoformat() + "Z", 'payload': job._payload } data = json.dumps(data) diff --git a/pyres/worker.py b/pyres/worker.py index fc42b12..ce65856 100644 --- a/pyres/worker.py +++ b/pyres/worker.py @@ -285,7 +285,7 @@ def working_on(self, job): logger.debug('marking as working on') data = { 'queue': job._queue, - 'run_at': str(int(time.mktime(datetime.datetime.now().timetuple()))), + 'run_at': datetime.datetime.utcnow().isoformat() + "Z", 'payload': job._payload } data = json.dumps(data) diff --git a/tests/__init__.py b/tests/__init__.py index 64f09eb..b1fa5d2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -119,6 +119,8 @@ def test_safe_str_to_class(self): assert safe_str_to_class('tests.Basic') == Basic self.assertRaises(ImportError, safe_str_to_class, 'test.Mine') self.assertRaises(ImportError, safe_str_to_class, 'tests.World') + # test that we can handle Ruby-compatible Module::Class names + assert safe_str_to_class('tests::Basic') == Basic # test that we'll use the class name as a module name if no # module name is provided (for Ruby compatibility) assert safe_str_to_class('tests') == tests