-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
Automatically reset "Started/Enquired" jobs to "Pedning" on Odoo Start #386
Comments
This kind of exists already. It's not just connected to Odoo starting up, but it's executed by the cron. queue/queue_job/data/queue_data.xml Lines 4 to 12 in 92eae4b
queue/queue_job/models/queue_job.py Lines 269 to 282 in 92eae4b
|
There hasn't been any activity on this issue in the past 6 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
A proposed implementation is in #423 |
Hi, where I work, we have the same problem. I've uploaded a pull request with the changes we've that solves this problem. I hope it can be as useful to you as it has been to us. |
@angelvilaplana thanks for your suggestion, that looks interesting @mlaitinen it is not really working. I'm not sure why. But this cron never do what it should do (cleanup stuck jobs) |
@ventor-dev You might have to tweak the cron method call arguments.
The cron job calls this method without arguments, which means that by default the job only deals with enqueued jobs, not started. In my experience more jobs are stuck in the "started" state, so just changing the cron call to
will take care of jobs stuck in the started state for more than 15 minutes. |
@mlaitinen thanks! |
Problem
When the Odoo server crashes or is otherwise force-stopped, running jobs are interrupted while the runner has no chance to know they have been aborted. In such situations, jobs may remain in started or enqueued state after the Odoo server is halted. Since the runner has no way to know if they are actually running or not, and does not know for sure if it is safe to restart the jobs, it does not attempt to restart them automatically. Such stale jobs therefore fill the running queue and prevent other jobs to start. You must therefore requeue them manually, either from the Jobs view, or by running the following SQL statement before starting Odoo:
update queue_job set state='pending' where state in ('started', 'enqueued')
Result of this - channel is lost as system is thinking that job is started, while it is not really doing anything
Solution
This problem exists since beginning of time (means from the beginning of queue_job). So I guess lot's of brilliant brains were considering different solutions. But I was thinking that problem sounds not so hard so be solved with below approach.
Currently we are running Job Runner Thread on Odoo Startup using this patch https://github.com/OCA/queue/blob/14.0/queue_job/jobrunner/__init__.py#L69
Than we will call initialize_database() method before we are starting processing jobs https://github.com/OCA/queue/blob/14.0/queue_job/jobrunner/runner.py#L501
And here we already have possibility to connect to the database. https://github.com/OCA/queue/blob/14.0/queue_job/jobrunner/runner.py#L414
So I suggest method that will run this script below before. We of course can make "SELECT FOR UPDATE" to be on the safe side and do not conflict with other processes that may query for the same records.
update queue_job set state='pending' where state in ('started', 'enqueued')
TO me this fix sounds safe.
But I believe @guewen you was considering this already. So before suggesting PR, maybe you see issues with above method?
The text was updated successfully, but these errors were encountered: