forked from Techsystech/web
[IMP] web_assets_warmup: Add database lock in post_load_hook
With dedicated services for odoo web and odoo cron we can get a serialize access error on startup14.0
parent
99940c6f90
commit
12ff724473
|
@ -1,9 +1,12 @@
|
||||||
# Copyright 2020 Camptocamp SA
|
# Copyright 2020 Camptocamp SA
|
||||||
|
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
from odoo import fields, registry
|
from odoo import fields, registry
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -32,6 +35,14 @@ def active_cron_assets():
|
||||||
model, res_id = row
|
model, res_id = row
|
||||||
if model != "ir.cron":
|
if model != "ir.cron":
|
||||||
return
|
return
|
||||||
|
# if there is already someone doing the same or already being executed
|
||||||
|
# we can skip the update of ir_cron
|
||||||
|
try:
|
||||||
|
with cr.savepoint():
|
||||||
|
cr.execute(
|
||||||
|
"SELECT * FROM ir_cron WHERE id = %s FOR UPDATE NOWAIT;",
|
||||||
|
(res_id,),
|
||||||
|
)
|
||||||
query = """
|
query = """
|
||||||
UPDATE ir_cron
|
UPDATE ir_cron
|
||||||
SET active=true, nextcall=%s, priority=%s
|
SET active=true, nextcall=%s, priority=%s
|
||||||
|
@ -46,6 +57,13 @@ def active_cron_assets():
|
||||||
cron_ref,
|
cron_ref,
|
||||||
nextcall,
|
nextcall,
|
||||||
)
|
)
|
||||||
|
except psycopg2.OperationalError as e:
|
||||||
|
if e.pgcode == "55P03":
|
||||||
|
logger.info(
|
||||||
|
"Cron '%s.%s' is currently being executed or updated",
|
||||||
|
cron_module,
|
||||||
|
cron_ref,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def post_load_hook():
|
def post_load_hook():
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
* Sébastien Alix <sebastien.alix@camptocamp.com>
|
* Sébastien Alix <sebastien.alix@camptocamp.com>
|
||||||
|
* Michael Tietz (MT Software) <mtietz@mt-software.de>
|
||||||
|
|
Loading…
Reference in New Issue