How to automatically requeue stuck jobs in “Started” or “Enqueued” state?

We are relying on our connector on the queue_job module. This module was developed by Community for already almost 10 years and proved to be the best solution for scalable integrations with another systems. 

However, as described in README.md to this module – this module has some issues and limitations. For example, sometimes if you restart Odoo in the middle of the job execution or job will time-out it will be stuck in “Started” ot “Enqueued” status. That can block other jobs from being executed. 

You either can manually Requeue job by click button or Action.

Odoo job form with arrows pointing to the Requeue Job button and to Requeue Jobs in the Action menu.

Or there is a mechanism to automatically “Requeue” stuck jobs automatically. In Settings → Automation → Schedule Actions menu (visible in Debug mode) there is job with name “Jobs Garbage Collector”

Odoo Scheduled Actions list filtered by 'garb', showing the Jobs Garbage Collector action for the Queue Job model.

It can be modified in a way that it will automatically requeue jobs in “Enqueued” or “Started” status. As on screenshot below

Odoo Jobs Garbage Collector scheduled action with arrows pointing to the 5 and 15 minute values in the Python Code.