-
-
Notifications
You must be signed in to change notification settings - Fork 535
[13.0][IMP] queue_job: use context to execute job (optional) #406
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
Conversation
e8fa70c to
b935f55
Compare
|
I didn't see this one before letting a comment on #407, my comment should actually be here. In #283 I proposed to store the context in the recordset instead of a new field. |
|
BTW, this is a long-awaited feature I think, so thank you to finally propose a PR :) |
@guewen Sorry for the (long) delay! I had some day off and a lot of work like everybody! I have to use a dedicated field to then restore it when the Or maybe I miss understand something? |
|
Hi @acsonefho, no worries! If you take a job signature, for instance class SaleOrder(models.Model):
_inherit = 'sale.order'
def do_random_stuff(self, partners, when=None):
# ...With When the By adding an encoder for the context in the JobEncoder and decoder, the context will automatically be stored in the existing JSON queue.job fields without adding an extra field, then "injected" into the decoded recordset. And it means, it will magically work for recordsets passed in The main thing to take care of, is that not everything can be encoded as JSON and the context can be a bit too liberal about this. We definitely want an allow-list for the context keys. records = JobSerialized(
string="Record(s)", readonly=True, base_type=models.BaseModel,
allowed_context_keys="_serialized_allowed_context_keys",
)
args = JobSerialized(readonly=True, base_type=tuple, allowed_context_keys="_serialized_allowed_context_keys")
kwargs = JobSerialized(readonly=True, base_type=dict, allowed_context_keys="_serialized_allowed_context_keys")
def _serialized_allowed_context_keys(self):
return ["tz", "lang", ...] # I don't remember what should really be thereThen, in the implementation of the job encoder, filter from this list. Is my explanation better this time ? :) |
|
Also, I don't see why we would not want the context ? |
|
I agree with @florian-dacosta , we can keep the context in any case IMO especially as we filter the context keys, and we can still customize the keys to filter by overriding the method that returns the list of keys to keep. |
Yes! Thank you very much! I'll improve in this way so! |
b935f55 to
a075727
Compare
Use the current company to trigger the job (+ add related tests)
Fill allowed_company_ids from context with the job's company instead of every allowed companies of the user.
Because most of the time, a job is related to only one company. And adding every allowed companies of the user into the context may load some unexpected records (during search for example). Because standards ir.rule use ['|',('company_id','=',False),('company_id', 'in', company_ids)] and this 'company_ids' is filled with every allowed companies from the context.
94ee0a0 to
68a6af3
Compare
|
@rousseldenis @guewen is this ready for merge? |
|
Hi @guewen any chance to review and merge this one? bit thx |
|
On my side, I really think keeping the context should be the default (actually I would not even put it as optional) I understand the backward compatibility argument, but the goal of queue job beeing just to do some action the same way but asynchronously, i believe that passing the context is more a fix than a new feature and it seems reasonable to change this behavior by default |
|
I also agree with florian, it's better (and simplier) to always pass the context |
|
@acsonefho any chance to update the PR? |
Yes I can do this but it could break the backward compatibility. |
68a6af3 to
2961b40
Compare
GSLabIt
left a comment
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.
LGTM
|
@sebastienbeau @guewen Can you review please? :) |
|
Hi @acsonefho, thanks, I understand your concern about backward compatibility. My concern with your proposal is that I don't really see how we can plan a path to a version where we store the context by default (with an allow-list). The argument you added in the enqueuing of the job introduces a change in the API, which will bring its own backward compatibility issues when we will not need it anymore (as the goal is to store it by default at some point). I would prefer not to have Here is a draft of the way I thought it would be easier to handle the transition : acsone#1 |
|
Hi @sebastienbeau @GSLabIt @florian-dacosta @francesco-ooops , Could you give your opinion on acsone#1 ? |
guewen
left a comment
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.
Discussion in acsone#1
|
#432 got merged |
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
When this parameter is set, queue_job always preserves the entire context. This honors the principle of least surprise, in that a developer can easily convert a record.method() call to record.with_delay().method() with the expectation that it will actually execute the same, simply at a later time. Fixes OCA#406.
In some case, we need to keep the context to execute the job.
On the
with_delay(...), add a parameterkeep_context(defaultTrue) to know if the context should be saved on the job.The
keep_contextparameter could be:False: do not usecontext;True(default value): use fullcontext;listof key: keep only given keys into thecontext.Je context is saved on the
JobEncoderand then restored withJobDecoder.Depends on #365 (about company)