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

a couple of Ruby-compatibility fixes #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyres/horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyres/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down