Skip to content

[13.0] Add ddmrp_cron_actions_as_job#81

Merged
OCA-git-bot merged 5 commits into
OCA:13.0from
camptocamp:13.0-ddmrp-auto-nfp-job
Feb 3, 2021
Merged

[13.0] Add ddmrp_cron_actions_as_job#81
OCA-git-bot merged 5 commits into
OCA:13.0from
camptocamp:13.0-ddmrp-auto-nfp-job

Conversation

@guewen

@guewen guewen commented Oct 29, 2020

Copy link
Copy Markdown
Member

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

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @JordiBForgeFlow, @LoisRForgeFlow,
some modules you are maintaining are being modified, check this out!

@guewen guewen changed the title Add ddmrp_cron_actions_as_job [13.0] Add ddmrp_cron_actions_as_job Oct 29, 2020
simahawk
simahawk previously approved these changes Oct 29, 2020

@simahawk simahawk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG

Comment thread ddmrp/tests/common.py
Comment thread ddmrp_cron_actions_as_job/models/stock_buffer.py Outdated
@guewen guewen changed the title [13.0] Add ddmrp_cron_actions_as_job [WIP][13.0] Add ddmrp_cron_actions_as_job Oct 29, 2020
@guewen

guewen commented Oct 29, 2020

Copy link
Copy Markdown
Member Author

OCA/queue#270 has a bug, so I'll propose a temporary alternative solution until I can fix this one

@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch from 24919eb to 50239d7 Compare November 2, 2020 07:29
@guewen
guewen dismissed simahawk’s stale review November 2, 2020 07:31

changed implementation, and need some work from me on the queue_job PRs to be ready

@guewen

guewen commented Nov 2, 2020

Copy link
Copy Markdown
Member Author

I pushed a new implementation that works by patching the method instead of relying on a decorator (see OCA/queue#270 (comment)). I still need to work on OCA/queue#274 for this to be ready.

@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch 2 times, most recently from 83f87dc to 5515cf3 Compare November 2, 2020 15:41
@guewen guewen changed the title [WIP][13.0] Add ddmrp_cron_actions_as_job [13.0] Add ddmrp_cron_actions_as_job Nov 2, 2020
@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch from 5515cf3 to b95bb31 Compare November 2, 2020 20:29
@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch from b95bb31 to 1c31e05 Compare February 2, 2021 15:23
@mileo

mileo commented Feb 2, 2021

Copy link
Copy Markdown
Member

Could you add the module to oca_requirements.txt?

@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch from 1c31e05 to 5c81d21 Compare February 3, 2021 07:49
@guewen

guewen commented Feb 3, 2021

Copy link
Copy Markdown
Member Author

Could you add the module to oca_requirements.txt?

done

@guewen
guewen force-pushed the 13.0-ddmrp-auto-nfp-job branch from 5c81d21 to a49002f Compare February 3, 2021 07:53
@guewen

guewen commented Feb 3, 2021

Copy link
Copy Markdown
Member Author

@JordiBForgeFlow @LoisRForgeFlow

I included the commits of #66 with a new commit fixing issues of #66:

  • Call commit once per chunk instead of once per record: commit flushes
    and clears the env, forcing a fetch of all the records of the chunk
    after each line.
  • Remove buffer.refresh() in cron_ddmrp(): this deprecated method
    calls invalidate_cache() without ids and field names, which forces
    a fetch of all the records of the chunk at each line. If it is
    required to invalidate something (but I could not find any
    explanation), we should invalidate only the ids and fields that needs
    invalidation (hopefully only non-stored computed fields). Or at the
    very least, do not fetch the 50 records of the browse at once but one
    by one (but that'd be a pity).

The duration of cron_ddmrp() (when generating jobs with ddmrp_cron_actions_as_job) goes from 8 minutes to 35 seconds.

Pay attention to the usage of refresh() / invalidate_cache() without specifying what to invalidate. It will force fetching again the records and computations, for all the pre-fetched ids. In the case of cron_actions, forcing to read the whole chunk again. As there was no indication why it was necessary, I removed it (when delaying a queue job it's never needed actually).

@guewen

guewen commented Feb 3, 2021

Copy link
Copy Markdown
Member Author

Pay attention to the usage of refresh() / invalidate_cache() without specifying what to invalidate. It will force fetching again the records and computations, for all the pre-fetched ids. In the case of cron_actions, forcing to read the whole chunk again. As there was no indication why it was necessary, I removed it (when delaying a queue job it's never needed actually).

As some tests failed, I looked again at this and found some fields to invalidate: ce5d553, these are the non-stored computed fields used by cron_actions

Guewen Baconnier and others added 5 commits February 3, 2021 09:54
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
commits and locking the buffers for too long.
* Call commit once per chunk instead of once per record: commit flushes
  and clears the env, forcing a fetch of all the records of the chunk
  after each line.
* Remove `buffer.refresh()` in cron_ddmrp(): this deprecated method
  calls `invalidate_cache()` without ids and field names, which forces
  a fetch of all the records of the chunk at each line. If it is
  required to invalidate something (but I could not find any
  explanation), we should invalidate only the ids and fields that needs
  invalidation (hopefully only non-stored computed fields). Or at the
  very least, do not fetch the 50 records of the browse at once but one
  by one (but that'd be a pity).

The duration of cron_ddmrp() (when generating jobs with
ddmrp_cron_actions_as_job) goes from 8 minutes to 35 seconds.
Fix tests:

* test_22_procure_recommended
* test_23_buffer_zones_all

It is possible that the invalidation is only required because of the
tests and would not be required at runtime. But this has been proposed
in the past: OCA#59

However, this commit tries to invalidate the less possible fields to
limit the computations and data to fetch again.

@jgrandguillaume jgrandguillaume left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM for what I can judge about.

@LoisRForgeFlow LoisRForgeFlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

Thanks for the detailed commit messages, it eases following the rational behind the changes.

Comment thread ddmrp/models/stock_buffer.py
@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@LoisRForgeFlow

Copy link
Copy Markdown
Contributor

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 13.0-ocabot-merge-pr-81-by-LoisRForgeFlow-bump-minor, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

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.

8 participants