Skip to content

Commit

Permalink
Merge 8c4bb2c into f42c57c
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed May 22, 2018
2 parents f42c57c + 8c4bb2c commit 1c396ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 2 additions & 2 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def _register_hook(self):
super(Base, self)._register_hook()
job_methods = [
method for __, method
in inspect.getmembers(self.__class__, predicate=inspect.ismethod)
in inspect.getmembers(self.__class__, predicate=inspect.isfunction)
if getattr(method, 'delayable', None)
]
for job_method in job_methods:
self.env['queue.job.function']._register_job(job_method)
self.env['queue.job.function']._register_job(self, job_method)

@api.multi
def with_delay(self, priority=None, eta=None,
Expand Down
10 changes: 5 additions & 5 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
_logger = logging.getLogger(__name__)


def channel_func_name(method):
return '<%s>.%s' % (method.__self__._name, method.__name__)
def channel_func_name(model, method):
return '<%s>.%s' % (model._name, method.__name__)


class QueueJob(models.Model):
Expand Down Expand Up @@ -104,7 +104,7 @@ def _compute_job_function(self):
for record in self:
model = self.env[record.model_name]
method = getattr(model, record.method_name)
channel_method_name = channel_func_name(method)
channel_method_name = channel_func_name(model, method)
func_model = self.env['queue.job.function']
function = func_model.search([('name', '=', channel_method_name)])
record.channel_method_name = channel_method_name
Expand Down Expand Up @@ -355,8 +355,8 @@ def _find_or_create_channel(self, channel_path):
return channel

@api.model
def _register_job(self, job_method):
func_name = channel_func_name(job_method)
def _register_job(self, model, job_method):
func_name = channel_func_name(model, job_method)
if not self.search_count([('name', '=', func_name)]):
channel = self._find_or_create_channel(job_method.default_channel)
self.create({'name': func_name, 'channel_id': channel.id})
10 changes: 10 additions & 0 deletions test_queue_job/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def job_b(self):
def job_sub_channel(self):
return

@property
def dummy_property(self):
""" Return foo
Only there to check that properties are compatible
with the automatic registration of job methods
and their default channels.
"""
return 'foo'


class TestRelatedAction(models.Model):

Expand Down
20 changes: 16 additions & 4 deletions test_queue_job/tests/test_job_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ def test_register_jobs(self):
self.env['queue.job.channel'].search([('name', '!=', 'root')]).unlink()

method_a = self.env['test.queue.channel'].job_a
self.env['queue.job.function']._register_job(method_a)
self.env['queue.job.function']._register_job(
self.env['test.queue.channel'],
method_a
)
method_b = self.env['test.queue.channel'].job_b
self.env['queue.job.function']._register_job(method_b)
self.env['queue.job.function']._register_job(
self.env['test.queue.channel'],
method_b
)

path_a = '<test.queue.channel>.job_a'
path_b = '<test.queue.channel>.job_b'
Expand All @@ -59,7 +65,10 @@ def test_channel_on_job(self):
self.env['queue.job.channel'].search([('name', '!=', 'root')]).unlink()

method = self.env['test.queue.channel'].job_a
self.env['queue.job.function']._register_job(method)
self.env['queue.job.function']._register_job(
self.env['test.queue.channel'],
method
)
path_a = '<%s>.%s' % (method.__self__.__class__._name, method.__name__)
job_func = self.function_model.search([('name', '=', path_a)])
self.assertEquals(job_func.channel, 'root')
Expand Down Expand Up @@ -92,7 +101,10 @@ def test_default_channel(self):
self.env['queue.job.channel'].search([('name', '!=', 'root')]).unlink()

method = self.env['test.queue.channel'].job_sub_channel
self.env['queue.job.function']._register_job(method)
self.env['queue.job.function']._register_job(
self.env['test.queue.channel'],
method
)
self.assertEquals(method.default_channel, 'root.sub.subsub')

path_a = '<%s>.%s' % (method.__self__.__class__._name, method.__name__)
Expand Down

0 comments on commit 1c396ea

Please sign in to comment.