Skip to content

Conversation

@sbidoul
Copy link
Member

@sbidoul sbidoul commented Jan 2, 2026

In this PR we cleanly separate the job acquisition (i.e. verifying the job is in the exepected state, marking it started and locking it) from job execution.

We also avoid trying to start the job if it is already locked by using SKIP LOCKED and exiting early. Indeed, in such situations, the job is likely already being handled by another worker so there is no point trying to start it, so we exit early and let it be handled either by the other worker or the dead job requeuer.

Following-up on #859 (comment)

maybe fixes #858

@OCA-git-bot
Copy link
Contributor

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

@sbidoul sbidoul force-pushed the 18.0-refactor-job-acquisition-sbi branch 2 times, most recently from 265b06e to 8d0b9c9 Compare January 2, 2026 12:56
@sbidoul sbidoul added this to the 18.0 milestone Jan 2, 2026
@sbidoul sbidoul changed the title [18.0] queue_job refactor job acquisition [18.0] queue_job: refactor job acquisition Jan 2, 2026
@sbidoul sbidoul force-pushed the 18.0-refactor-job-acquisition-sbi branch 2 times, most recently from eff0043 to d6c907a Compare January 2, 2026 17:51
@sbidoul sbidoul marked this pull request as ready for review January 2, 2026 17:55
@sbidoul sbidoul force-pushed the 18.0-refactor-job-acquisition-sbi branch from d6c907a to 367ab80 Compare January 2, 2026 18:00
" to make this tests work",
)

return job
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to JobCommonCase

@sbidoul
Copy link
Member Author

sbidoul commented Jan 2, 2026

This is ready to review.

It can be tested with a small number of workers and a root channel capacity greater than the number of workers and test jobs of duration >= 10 sec.

If the test graph has enough parallelism, you will see warnings about dead jobs being requeued (the jobs in state enqueued that are not picked up by workers in due time), but each job should execute only once.

Example: odoo --workers=3, root:10 and http://odoo/queue_job/create_test_job?size=20&job_duration=10.

The _acquire_job method is now simple enough that it can be unit tested. Next I may try refactoring the perform job part buy its a bit scarier :) But first, merging 19.0.

Copy link
Contributor

@hoangtrann hoangtrann left a comment

Choose a reason for hiding this comment

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

Code LGTM

@hoangtrann
Copy link
Contributor

I've also tested this locally and and it seems to work as intended
image

@sbidoul sbidoul force-pushed the 18.0-refactor-job-acquisition-sbi branch from 367ab80 to 69acde4 Compare January 3, 2026 09:09
In this commit we cleanly separate the job acquisition (i.e. verifying the job is in the exepected state, marking it started and locking it) from job execution.

We also avoid trying to start the job if it is already locked by using SKIP LOCKED
and exiting early. Indeed in such situations the job is likely already being handled by another worker so there is no point trying to start it, so we exit early
and let it be handled either by the other worker or the dead job requeuer.
Extract the logic to run one job out of the /queue_job/runjob route.
Towards making this logic reusable in other job executors.
@sbidoul sbidoul force-pushed the 18.0-refactor-job-acquisition-sbi branch from 69acde4 to 9937ed0 Compare January 3, 2026 10:37
@sbidoul
Copy link
Member Author

sbidoul commented Jan 3, 2026

Thanks for the review and testing @hoangtrann !

I added a couple of commits to split out the job execution logic to class method so it is reusable from outside the controller and open the door to experiments such as #871.

@sbidoul
Copy link
Member Author

sbidoul commented Jan 3, 2026

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 18.0-ocabot-merge-pr-866-by-sbidoul-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 9a57664 into OCA:18.0 Jan 3, 2026
6 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

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

@sbidoul sbidoul deleted the 18.0-refactor-job-acquisition-sbi branch January 3, 2026 15:18
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.

After requeueing a job, first run often fails to update date_done with concurrent error

4 participants