Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Get attributes on the class instead of recordsets #50

Merged
merged 1 commit into from
Feb 8, 2018
Merged
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
17 changes: 5 additions & 12 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ class Base(models.AbstractModel):
def _register_hook(self):
""" register marked jobs """
super(Base, self)._register_hook()
job_methods = set()
for attr_name in dir(self):
# _cache on models is a lazy_property which raises an
# AssertionError when called on a empty model, just skip it.
if attr_name == '_cache':
continue
try:
attr = getattr(self, attr_name)
except AttributeError:
continue
if inspect.ismethod(attr) and getattr(attr, 'delayable', None):
job_methods.add(attr)
job_methods = [
method for __, method
in inspect.getmembers(self.__class__, predicate=inspect.ismethod)
Copy link
Member

@guewen guewen May 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the class, the methods are not yet methods but functions, because what we are inspecting at this point is the decorated function I guess.

if getattr(method, 'delayable', None)
]
for job_method in job_methods:
self.env['queue.job.function']._register_job(job_method)

Expand Down