refactor: update server logic and adjust exercise, extra-addons files
Some checks are pending
Setup Native Action / native (3.12.7) (push) Waiting to run
Setup Native Action / docker (3.12.7) (push) Waiting to run

This commit is contained in:
KaySar12 2025-06-21 10:14:58 +07:00
parent 8923642a72
commit 9b1bb0a7e1
3 changed files with 30 additions and 30 deletions

@ -1 +1 @@
Subproject commit 70ae66ee4b80ac134bedbe3123eebe7e973e984a
Subproject commit f334b0a2019474ec0e031cb87cdc2ed020d8142f

@ -1 +1 @@
Subproject commit 265e2490e92b945b20ddb11b9761fef5896ce518
Subproject commit 546b2637171effc29b51dc1a13651c3014c8a67a

View File

@ -448,36 +448,36 @@ class ThreadedServer(CommonServer):
# On NOTIFY, all workers are awaken at the same time, sleeping
# just a bit prevents they all poll the database at the exact
# same time. This is known as the thundering herd effect.
pass
# from odoo.addons.base.models.ir_cron import ir_cron
# conn = odoo.sql_db.db_connect('postgres')
# with conn.cursor() as cr:
# pg_conn = cr._cnx
# # LISTEN / NOTIFY doesn't work in recovery mode
# cr.execute("SELECT pg_is_in_recovery()")
# in_recovery = cr.fetchone()[0]
# if not in_recovery:
# cr.execute("LISTEN cron_trigger")
# else:
# _logger.warning("PG cluster in recovery mode, cron trigger not activated")
# cr.commit()
from odoo.addons.base.models.ir_cron import ir_cron
conn = odoo.sql_db.db_connect('postgres')
with conn.cursor() as cr:
pg_conn = cr._cnx
# LISTEN / NOTIFY doesn't work in recovery mode
cr.execute("SELECT pg_is_in_recovery()")
in_recovery = cr.fetchone()[0]
if not in_recovery:
cr.execute("LISTEN cron_trigger")
else:
_logger.warning("PG cluster in recovery mode, cron trigger not activated")
cr.commit()
# while True:
# select.select([pg_conn], [], [], SLEEP_INTERVAL + number)
# time.sleep(number / 100)
# pg_conn.poll()
while True:
select.select([pg_conn], [], [], SLEEP_INTERVAL + number)
time.sleep(number / 100)
pg_conn.poll()
registries = odoo.modules.registry.Registry.registries
_logger.debug('cron%d polling for jobs', number)
for db_name, registry in registries.d.items():
if registry.ready:
thread = threading.current_thread()
thread.start_time = time.time()
try:
ir_cron._process_jobs(db_name)
except Exception:
_logger.warning('cron%d encountered an Exception:', number, exc_info=True)
thread.start_time = None
# registries = odoo.modules.registry.Registry.registries
# _logger.debug('cron%d polling for jobs', number)
# for db_name, registry in registries.d.items():
# if registry.ready:
# thread = threading.current_thread()
# thread.start_time = time.time()
# try:
# ir_cron._process_jobs(db_name)
# except Exception:
# _logger.warning('cron%d encountered an Exception:', number, exc_info=True)
# thread.start_time = None
def cron_spawn(self):
""" Start the above runner function in a daemon thread.