Uh oh!
There was an error while loading. Please reload this page.
[16.0][IMP] queue_job: remove dead jobs requeuer cron and automatically requeue dead jobs - #716
Conversation
OCA-git-bot
commented
Dec 6, 2024
Hi @guewen, |
sbidoul
left a comment
There was a problem hiding this comment.
This looks very promising!
A few thoughts:
- There is a Caveat comment in
runner.pythat needs updating. - This should handle the
enqueuedstate too, which is the state when the runner has decided that a jobs needs to run but then/queue_job/runjobcontroller has not set it started yet. This state normally exists for a very short time, but I have seen situations where the workers are overloaded and take time to accept/queue_job/runjobrequests then die, leaving jobs inenqueuedstate forever. - Since there are two race conditions between
enqueuedandstarted, and betweenstartedand the time the job transaction actually starts with the lock, I wonder if we should not introduce a small elapsed time condition (10s?) inreset_dead_jobs. May be based ondate_enqueued.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AnizR
commented
Dec 6, 2024
Thank you for your suggestions. I have implemented the necessary corrections. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| if self.max_retries and self.retry >= self.max_retries: | ||
| raise FailedJobError("Max. retries (%d) reached" % (self.max_retries)) |
There was a problem hiding this comment.
Why adding this? This sounds unrelated.
There was a problem hiding this comment.
The check that max_retries is greater than retry was done only when a RetryableJobError was raised during the execution of the job.
Since I am increasing the retry when re-queuing a job that was killed, I need to do the check before peforming the job, not only when raising an exception.
Moreover, I think that it doesn't make sense to perform the check only when an exception has been raised 🤔
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
310847e to
0102273CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f98c856 to
8edf042CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
guewen
left a comment
There was a problem hiding this comment.
Thanks for tackling this old issue, I like this elegant solution. It should be quite optimized also. Congrats for this work
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <odoo> | ||
| <data noupdate="1"> | ||
| <record id="ir_cron_queue_job_garbage_collector" model="ir.cron"> |
There was a problem hiding this comment.
Should this become
<deleteid="ir_cron_queue_job_garbage_collector"model="ir.cron"/>to clean up upgrades / avoid filling cron logs with errors since requeue_stuck_jobs method is gone?
There was a problem hiding this comment.
I have archived the cron in the pre-migration.py. Therefore, there won't be any error.
I always prefer to archive (set active to false) rather than deleting.
sbidoul
commented
Dec 11, 2024
@AnizR I think we can also remove the |
AnizR
commented
Dec 13, 2024
Yes, jobs that have not been started will be re-queued by my new mechanism. |
Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
AnizR
commented
Feb 26, 2025
I am happy to contribute and see that it works and is used 👍 I have also used this PR on a production environment without any issue. |
sbidoul
commented
Feb 26, 2025
@amh-mw have your concerns been addressed? |
sbidoul
commented
Feb 26, 2025
Let's go. /ocabot merge minor |
OCA-git-bot
commented
Feb 26, 2025
What a great day to merge this nice PR. Let's do it! |
OCA-git-bot
commented
Feb 26, 2025
This PR has the |
OCA-git-bot
commented
Feb 26, 2025
Congratulations, your PR was merged at a28339b. Thanks a lot for contributing to OCA. ❤️ |
sbidoul
commented
Feb 28, 2025
FW port to 17.0 in #748 |
* Job Queue Lock model added to track jobs being actively processed by Odoo * Any job not being actively worked on will either be: * Requeued, if max_retries not reached * Marked as failed, if max_retries reached * Covers cases where the Odoo instance is restarted or a job is killed by Odoo due to exceeding the limit_time_cpu setting Backport of enhancement from Odoo 16 PR on OCA: OCA#716
Goal
Automatically re-queue jobs that have been started but whose worker have been killed.
And rely on Odoo's limit_time_cpu and limit_time_real for job execution.
Technical explanation
Everything relies on a new table
queue_job_lockswhich contains ids of jobs that have been started.When a job is executed, its row
queue_job_locksis locked.If a row is in
queue_job_lockswith astate='started'but not locked, it is either:Using this information, we can re-queue these jobs.
Why not lock directly in the `queue_job' table?
This was tried in #423 but it wasn't working when a job was raising an error.
It seems that the row was locked and it tried to write on the row to set as
failedbefore committing.Improve current behavior
Re-queue jobs that have been killed but increment their 'retries' to avoid having a job that is always get killed in infinite re-queuing.