mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00

Mostly for tests: it can be really difficult to correlate issues as there are 3 different processes involved (the test runner, the odoo being tested, and dummy-central (as github)) and the intermixing of logs between the test driver and the odoo being tested is not *amazing*. - `pytest-opentelemetry`'s `--export-traces` is the signal for running tests with tracing enabled, that way just having `pytest-opentelemetry` installed does not do anything untowards. - Until chrisguidry/pytest-opentelemetry#34 is merged, should probably use the linked branch as the default / base mode of having a single trace for the entire test suite is not great when there are 460 tests, especially as local clients (opentelemetry-desktop-viewer, venator) mostly work on traces and aren't very good at zooming on *spans* at least currently. - Additionally, the conftest plugin adds hooks for propagating through the xmlrpc client (communications with odoo) and enables the requests instrumentor from the opentelemetry python contribs. - The dummy `saas_worker` was moved into the filesystem, that makes it easier to review and update. - A second such module was added for the otel instrumentation *of the odoo under test*, that instruments psycopg2, requests, wsgi, and the server side of xmlrpc. - The git ops were instrumented directly in runbot_merge, as I've tried to keep `saas_tracing` relatively generic, in case it could be moved to community or used by internal eventually. Some typing was added to the conftest hooks and fixtures, and they were migrated from tmpdir (py.path) to tmp_path (pathlib) for consistency, even though technically the `mkdir` of pathlib is an annoying downgrade. Fixes #835
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import builtins
|
|
import logging
|
|
import threading
|
|
|
|
import psycopg2
|
|
|
|
import odoo
|
|
from odoo import models
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Base(models.AbstractModel):
|
|
_inherit = 'base'
|
|
|
|
def run_crons(self):
|
|
builtins.current_date = self.env.context.get('current_date')
|
|
builtins.forwardport_merged_before = self.env.context.get('forwardport_merged_before')
|
|
self.env['ir.cron']._process_jobs(self.env.cr.dbname)
|
|
del builtins.forwardport_merged_before
|
|
return True
|
|
|
|
|
|
class IrCron(models.Model):
|
|
_inherit = 'ir.cron'
|
|
|
|
@classmethod
|
|
def _process_jobs(cls, db_name):
|
|
t = threading.current_thread()
|
|
try:
|
|
db = odoo.sql_db.db_connect(db_name)
|
|
t.dbname = db_name
|
|
with db.cursor() as cron_cr:
|
|
# FIXME: override `_get_all_ready_jobs` to directly lock the cron?
|
|
while job := next((
|
|
job
|
|
for j in cls._get_all_ready_jobs(cron_cr)
|
|
if (job := cls._acquire_one_job(cron_cr, (j['id'],)))
|
|
), None):
|
|
# take into account overridings of _process_job() on that database
|
|
registry = odoo.registry(db_name)
|
|
registry[cls._name]._process_job(db, cron_cr, job)
|
|
cron_cr.commit()
|
|
|
|
except psycopg2.ProgrammingError as e:
|
|
raise
|
|
except Exception:
|
|
_logger.warning('Exception in cron:', exc_info=True)
|
|
finally:
|
|
if hasattr(t, 'dbname'):
|
|
del t.dbname
|