From 35f057454f468c20eeab42fc62070712773fa840 Mon Sep 17 00:00:00 2001 From: toby cabot Date: Wed, 1 Jul 2015 18:22:57 -0400 Subject: [PATCH 1/2] handle ruby-style Module::Class names Ruby uses "::" to separate modules from classes, while python uses "." so we'll sniff the queued class name for "::" and if it's there then we're probably handling a job that was queued by Ruby. --- pyres/__init__.py | 9 ++++++++- tests/__init__.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) 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/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 From 65c3e341345ecbd75e4b01cfafdc2e1bd784695f Mon Sep 17 00:00:00 2001 From: toby cabot Date: Thu, 17 Nov 2016 16:57:18 -0500 Subject: [PATCH 2/2] Write run_at in a resque-compatible format Resque expects that the run_at value will be an ISO8601 string in UTC. Pyres was writing seconds since the epoch, which caused resque-web to crash. --- pyres/horde.py | 2 +- pyres/worker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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)