Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions queue_job/migrations/10.0.1.0.0/end-migration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
import logging

from odoo import api, SUPERUSER_ID
from odoo.addons.queue_job.job import DONE


def migrate(cr, version):
Expand All @@ -13,6 +13,7 @@ def migrate(cr, version):
if not version:
return
env = api.Environment(cr, SUPERUSER_ID, {})
logger = logging.getLogger("odoo.addons.queue.migrations")
QueueJob = env['queue.job']
groups = QueueJob.read_group(
[], ['model_name', 'method_name'], ['model_name', 'method_name'],
Expand All @@ -31,6 +32,21 @@ def migrate(cr, version):
})
# recompute func_string after other addons have adapted their
# args/kwargs/record_ids
records = QueueJob.search([('state', 'not in', [DONE])])
records._recompute_todo(QueueJob._fields['func_string'])
records.recompute()
records = env["queue.job"].search([])
total = len(records)
count = 0
error = 0
for record in records:
count += 1
if not count % 1000:
logger.info("Recomputing func_string of job %s of %s",
count, total)
try:
record._compute_func_string()
except KeyError: # unknown model or non-compliant arguments
error += 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please log the error so that I see what's going wrong here

Copy link
Author

@StefanRijnhart StefanRijnhart May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this one OCA#341 (comment) but I've pushed a logging commit. Restarting the migration now with this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm attaching the relevant logging to the ticket.

logger.debug("Could not recompute func_string of queue.job#%s",
record.id)

if error:
logger.warning("Could not recompute func_string of %s jobs", error)
17 changes: 13 additions & 4 deletions queue_job/migrations/10.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
from cPickle import Unpickler
from StringIO import StringIO
from odoo.addons.queue_job.job import DONE
from odoo.addons.queue_job.fields import JobEncoder


Expand All @@ -32,16 +31,24 @@ def migrate_args_kwargs(cr):
(func_name, args, kwargs) pickled in a binary string. Ignore done
jobs for performance reasons"""
cr.execute(
'select id, func from queue_job where state not in %s',
(tuple([DONE]),),
'select id, func from queue_job'
)
for _id, func in cr.fetchall():
records = cr.fetchall()
total = len(records)
count = 0
error = 0
for _id, func in records:
count += 1
if not count % 1000:
_logger.info("Parsing arguments of job %s of %s",
count, total)
try:
func_name, args, kwargs = Unpickler(StringIO(func)).load()
except Exception:
_logger.exception(
'Failed to parse func column for queue_job#%s', _id,
)
error += 1
continue
cr.execute(
'update queue_job set args=%s, kwargs=%s where id=%s',
Expand All @@ -51,3 +58,5 @@ def migrate_args_kwargs(cr):
_id,
),
)
if error:
_logger.warning("Could not parse arguments of %s jobs", error)