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

[13.0] Add method to patch a method to be automatically delayed #275

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

guewen
Copy link
Member

@guewen guewen commented Nov 2, 2020

This patch method has to be called in _register_hook.

When a method is patched, any call to the method will not directly
execute the method's body, but will instead enqueue a job.

When a context_key is set when calling _patch_job_auto_delay,
the patched method is automatically delayed only when this key is
True in the caller's context. It is advised to patch the method
with a context_key, because making the automatic delay in any
case
can produce nasty and unexpected side effects (e.g. another
module calls the method and expects it to be computed before doing
something else, expecting a result, ...).

A typical use case is when a method in a module we don't control is called
synchronously in the middle of another method, and we'd like all the calls
to this method become asynchronous.

It relies on #274 that deprecates the @job decorator
Replaces #270

Closes #238

guewen added a commit to camptocamp/ddmrp that referenced this pull request Nov 2, 2020
It makes every calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
guewen added a commit to camptocamp/ddmrp that referenced this pull request Nov 2, 2020
It makes every calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
@guewen
Copy link
Member Author

guewen commented Nov 2, 2020

TODO: Currently, the patched method is automatically delayed and can be forced to be synchrone with a context key. We should probably make it explicit by expecting a key in the context to use autodelay: if someone calls the method elsewhere, and expect to have the computation of the method to be done synchronously, having a delay fully automatic can introduce silent and vicious errors.

@guewen guewen force-pushed the 13.0-job-patch-auto-delay branch 2 times, most recently from b0aca1e to de019cc Compare November 2, 2020 15:31
guewen added a commit to camptocamp/ddmrp that referenced this pull request Nov 2, 2020
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
@guewen guewen force-pushed the 13.0-job-patch-auto-delay branch 2 times, most recently from cd01fd1 to 8a5234d Compare November 2, 2020 20:26
guewen added a commit to camptocamp/ddmrp that referenced this pull request Nov 2, 2020
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
@sebalix
Copy link
Contributor

sebalix commented Nov 5, 2020

@guewen is this PR still a draft?

@guewen
Copy link
Member Author

guewen commented Nov 5, 2020

@guewen is this PR still a draft?

Well, it's ready but as I had to include commits from #274 , I wasn't sure how to proceed

This patch method has to be called in ``_register_hook``.

When a method is patched, any call to the method will not directly
execute the method's body, but will instead enqueue a job.

When a ``context_key`` is set when calling ``_patch_job_auto_delay``,
the patched method is automatically delayed only when this key is
``True`` in the caller's context. It is advised to patch the method
with a ``context_key``, because making the automatic delay *in any
case* can produce nasty and unexpected side effects (e.g. another
module calls the method and expects it to be computed before doing
something else, expecting a result, ...).

A typical use case is when a method in a module we don't control is called
synchronously in the middle of another method, and we'd like all the calls
to this method become asynchronous.

It relies on OCA#274 that deprecates the
`@job` decorator.
@guewen guewen marked this pull request as ready for review November 12, 2020 15:08
@guewen
Copy link
Member Author

guewen commented Nov 12, 2020

note to myself: worth to add a doc in readme

Copy link
Member

@sebastienbeau sebastienbeau left a comment

Choose a reason for hiding this comment

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

LGTM great improvement ! queue_job rocks !

@simahawk
Copy link
Contributor

/ocabot merge minor

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 13.0-ocabot-merge-pr-275-by-simahawk-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit f9b1cd1 into OCA:13.0 Jan 26, 2021
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 8fe68a4. Thanks a lot for contributing to OCA. ❤️

guewen added a commit to camptocamp/ddmrp that referenced this pull request Feb 2, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
guewen added a commit to camptocamp/ddmrp that referenced this pull request Feb 2, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
guewen added a commit to camptocamp/ddmrp that referenced this pull request Feb 3, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
guewen added a commit to camptocamp/ddmrp that referenced this pull request Feb 3, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
guewen added a commit to camptocamp/ddmrp that referenced this pull request Feb 3, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
DavidBForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request Mar 17, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
DavidBForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request Mar 19, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
DavidBForgeFlow pushed a commit to ForgeFlow/ddmrp-1 that referenced this pull request Mar 19, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
DavidBForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request May 27, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
ChrisOForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request Dec 16, 2021
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
JordiBForgeFlow pushed a commit to OCA/ddmrp that referenced this pull request Feb 18, 2022
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
BernatPForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request Jun 6, 2023
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
LoisRForgeFlow pushed a commit to ForgeFlow/ddmrp-1 that referenced this pull request Mar 11, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
patrickrwilson pushed a commit to ursais/ddmrp that referenced this pull request Apr 18, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
Vandan-OSI pushed a commit to ursais/ddmrp that referenced this pull request May 6, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
DavidJForgeFlow pushed a commit to ForgeFlow/ddmrp-1 that referenced this pull request Jun 13, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
ArnauCForgeFlow pushed a commit to ForgeFlow/ddmrp that referenced this pull request Jul 18, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
ArnauCForgeFlow pushed a commit to ForgeFlow/ddmrp-1 that referenced this pull request Jul 18, 2024
It makes calls to "cron_actions" run in queue jobs.

The jobs have an identity key with "identity_exact", meaning that only
one occurence of a job for the same buffer with the same arguments
(only_nfp) will be created at a time (e.g. when the state of a
stock.move is changed several times in the same transaction or in
a different transaction in a short timeframe).

It needs OCA/queue#274 and
OCA/queue#275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] Add job_auto_delay decorator
5 participants