Merge lp:~camptocamp/openerp-connector/7.0-delay-return-uuid-lep into lp:~openerp-connector-core-editors/openerp-connector/7.0

Proposed by Leonardo Pistone
Status: Merged
Approved by: Guewen Baconnier @ Camptocamp
Approved revision: 604
Merged at revision: 606
Proposed branch: lp:~camptocamp/openerp-connector/7.0-delay-return-uuid-lep
Merge into: lp:~openerp-connector-core-editors/openerp-connector/7.0
Diff against target: 60 lines (+20/-5)
2 files modified
connector/queue/job.py (+14/-4)
connector/tests/test_job.py (+6/-1)
To merge this branch: bzr merge lp:~camptocamp/openerp-connector/7.0-delay-return-uuid-lep
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+201448@code.launchpad.net

Commit message

[imp] when delaying function and creating a job, return the job uuid.
This should not break anything because before everything returned None.

Description of the change

The delay() function returns None.

This changes it so that it returns the new job UUID.

I changed an existing unit test to cover that.

Thanks!

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Nice! Thanks

review: Approve (code review)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Guewen,

FYI, I gave a quick look to what celery does in that case, and they return an AsynchResult instance you can use to ask things including the uuid.

just the uuid should do for now, still.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'connector/queue/job.py'
2--- connector/queue/job.py 2013-11-18 14:28:23 +0000
3+++ connector/queue/job.py 2014-01-13 16:10:56 +0000
4@@ -103,13 +103,20 @@
5
6 def enqueue(self, func, model_name=None, args=None, kwargs=None,
7 priority=None, eta=None, max_retries=None, description=None):
8+ """Create a Job and enqueue it in the queue. Return the job uuid.
9+
10+ This expects the arguments specific to the job to be already extracted
11+ from the ones to pass to the job function.
12+
13+ """
14 job = Job(func=func, model_name=model_name, args=args, kwargs=kwargs,
15 priority=priority, eta=eta, max_retries=max_retries, description=description)
16 job.user_id = self.session.uid
17 self.store(job)
18+ return job.uuid
19
20 def enqueue_resolve_args(self, func, *args, **kwargs):
21- """Create a Job and enqueue it in the queue"""
22+ """Create a Job and enqueue it in the queue. Return the job uuid."""
23 priority = kwargs.pop('priority', None)
24 eta = kwargs.pop('eta', None)
25 model_name = kwargs.pop('model_name', None)
26@@ -638,8 +645,11 @@
27
28 """
29 def delay(session, model_name, *args, **kwargs):
30- OpenERPJobStorage(session).enqueue_resolve_args(func,
31- model_name=model_name,
32- *args, **kwargs)
33+ """Enqueue the function. Return the uuid of the created job."""
34+ return OpenERPJobStorage(session).enqueue_resolve_args(
35+ func,
36+ model_name=model_name,
37+ *args,
38+ **kwargs)
39 func.delay = delay
40 return func
41
42=== modified file 'connector/tests/test_job.py'
43--- connector/tests/test_job.py 2013-11-16 14:04:11 +0000
44+++ connector/tests/test_job.py 2014-01-13 16:10:56 +0000
45@@ -164,9 +164,14 @@
46 def test_job_delay(self):
47 self.cr.execute('delete from queue_job')
48 deco_task = job(task_a)
49- task_a.delay(self.session, 'res.users')
50+ job_uuid = task_a.delay(self.session, 'res.users')
51 stored = self.queue_job.search(self.cr, self.uid, [])
52 self.assertEqual(len(stored), 1)
53+ stored_brw = self.queue_job.browse(self.cr, self.uid, stored)
54+ self.assertEqual(
55+ stored_brw[0].uuid,
56+ job_uuid,
57+ 'Incorrect returned Job UUID')
58
59 def test_job_delay_args(self):
60 self.cr.execute('delete from queue_job')