-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
[WIP] Rework jobs queue #212
Conversation
Now that we have a root model 'base', we can properly override the methods to fire the events.
The reason of being for the separation was to be able to support another storage than postgres if needed. Nothing has ever been done in this way and the current backend storage (postgres) has proved to be efficient.
670eea6
to
3a5b253
Compare
3a5b253
to
bdbf505
Compare
I have some design issues for the jobs on Model methods. Currently this is how we delay a function: @job
def my_func(env,recordset, a, k=None):
pass
my_func.delay(env, recordset, 1, k=1) # asynchronous
my_func(env, recordset, 1, k=1) # synchronous
# and when we have additional parameters for the job handling they are added to
# the kwargs (so there are *reserved* kwargs):
my_func.delay(env, recordset, 1, k=1, priority=1, description='test') On Model methods, according to this definition: class MyModel(models.Model):
_name = 'my.model'
@api.multi
@job
def my_method(self, a, k=1):
pass We would have: self.env['my.model'].my_method.delay(1, k=1) # might be ok
recordset = self.env['my.model'].browse(1)
recordset.my_method.delay(1, k=1) # not ok! In the last call, the We'll need to change the delay API if we want to support jobs on Model methods, A. recordset.prepare_delay(self.env['my.model'].my_method, priority=10, description='test').delay(1, k=1) pros:
cons:
B. from odoo.addons.queue_job.job import prepare_delay
prepare_delay(recordset.my_method, priority=10, description='test').delay(1, k=1) pros:
cons:
C. recordset.with_delay(priority=10, description='test').my_method(1, k=1)
# with_delay returns a instance of a DelayableRecordset, the trick being to
# override `__getattr__` to find the method an the recordset and delay it pros:
cons:
@lmignon @sbidoul @sebastienbeau @lasley your opinions? any other idea? |
@lmignon Okay, I didn't put any thought in this part actually, I was first interested in how we want to use the BTW I'm not sure how the |
I like C. Will it work with model methods? Delaying standalone functions is relatively rare, and could be done with a specific method on |
Could be done on an
Yes, both |
Implemented C in 2794886. Still rough in the edges and now need to be simplified with the removal of the standalone |
bd69167
to
5821f49
Compare
The next commits will remove the support of '.delay()' on standalone methods. It will simplify the code as we now support the 2. Standalone jobs not on a particular model will need to be done on AbstractModel created on purpose, so we will only support jobs on models.
5821f49
to
7beb5aa
Compare
The related actions are now methods of the queue.job model. They are configured using their name instead of being passed as a function.
(note: tests are green but I didn't tested for real yet) |
Yes 👍 for a queue or connector-queue repository |
|
||
class JobSerialized(fields.Field): | ||
""" Serialized fields provide the storage for sparse fields. """ | ||
type = 'serialized' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guewen you must chose and other type name since this value is already used by the fields.Serialized
in Odoo. https://github.com/odoo/odoo/blob/10.0/odoo/fields.py#L2372
It's important to put a discriminant value for the type since it is used as key to register your field in the field's registry https://github.com/odoo/odoo/blob/10.0/odoo/fields.py#L104. This registry is used for example to fill the selection list when you add a new field with the UI....
This key is used to register the new field in the fields registry so it is important to have a unique type.
Moved in OCA/queue#1 |
Queue Job seem OK, I'm testing it working with base_import_async. But for my use cases/models connector.event is needed. So I think we also need to extract event from connector, not only in my models, but in many situations the use of events to trigger jobs is very usefull. I rewrote base_import_async depending on queue_job besides of connector, but in my case I can't progress without events.. Is there anyone working on it? Should I start this extraction, and if the answer is yes, where shoud I put the pull request? |
@danieltorres7 please move on OCA/queue#1 |
Still to do:
queue_job
]: allow todelay
Model methodsqueue_job
]: use json instead of pickle for the job arguments (recordsets should be serialized as['model.name', [ids]]
)queue_job
]: return job record instead of uuid on delayqueue_job
]: make related actions methods of thequeue.job
modelDepends on #211 (only commits after 3599912 are relevant).