Last active
March 3, 2023 22:44
-
-
Save litnimax/4af059f018f819494268e5724bd02d8f to your computer and use it in GitHub Desktop.
Odoo: suppress warnings WARNING 8_orders.x.x odoo.addons.base.models.ir_cron: Skipping database 8_x.x as its base version is not 16.0.1.3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import psycopg2 | |
import threading | |
import odoo | |
class BadVersion(Exception): | |
pass | |
class BadModuleState(Exception): | |
pass | |
_logger = logging.getLogger(__name__) | |
class IrCron(odoo.models.Model): | |
_inherit = 'ir.cron' | |
@classmethod | |
def _process_jobs(cls, db_name): | |
""" Execute every job ready to be run on this database. """ | |
try: | |
db = odoo.sql_db.db_connect(db_name) | |
threading.current_thread().dbname = db_name | |
with db.cursor() as cron_cr: | |
cls._check_version(cron_cr) | |
jobs = cls._get_all_ready_jobs(cron_cr) | |
if not jobs: | |
return | |
cls._check_modules_state(cron_cr, jobs) | |
for job_id in (job['id'] for job in jobs): | |
try: | |
job = cls._acquire_one_job(cron_cr, (job_id,)) | |
except psycopg2.extensions.TransactionRollbackError: | |
cron_cr.rollback() | |
_logger.debug("job %s has been processed by another worker, skip", job_id) | |
continue | |
if not job: | |
_logger.debug("another worker is processing job %s, skip", job_id) | |
continue | |
_logger.debug("job %s acquired", job_id) | |
# take into account overridings of _process_job() on that database | |
registry = odoo.registry(db_name) | |
registry[cls._name]._process_job(db, cron_cr, job) | |
_logger.debug("job %s updated and released", job_id) | |
except BadVersion: | |
_logger.info('Skipping database %s as its base version is not %s.', db_name, BASE_VERSION) | |
except BadModuleState: | |
_logger.info('Skipping database %s because of modules to install/upgrade/remove.', db_name) | |
except psycopg2.ProgrammingError as e: | |
if e.pgcode == '42P01': | |
# Class 42 — Syntax Error or Access Rule Violation; 42P01: undefined_table | |
# The table ir_cron does not exist; this is probably not an OpenERP database. | |
_logger.info('Tried to poll an undefined table on database %s.', db_name) | |
else: | |
raise | |
except Exception: | |
_logger.warning('Exception in cron:', exc_info=True) | |
finally: | |
if hasattr(threading.current_thread(), 'dbname'): | |
del threading.current_thread().dbname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment