Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][BCK] queue_job: unify no delay option / unified views / don't raise warning for valid context #682

Open
wants to merge 4 commits into
base: 12.0
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions queue_job/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,14 @@ Based on this configuration, we can tell that:
When you are developing (ie: connector modules) you might want
to bypass the queue job and run your code immediately.

To do so you can set `TEST_QUEUE_JOB_NO_DELAY=1` in your enviroment.
To do so you can set `QUEUE_JOB_NO_DELAY=1` in your enviroment.

**Bypass jobs in tests**

When writing tests on job-related methods is always tricky to deal with
delayed recordsets. To make your testing life easier
you can set `test_queue_job_no_delay=True` in the context.
delayed recordsets. To make your testing life easier,
or to run a delayed action immediately,
you can set `queue_job__no_delay=True` in the context.

Tip: you can do this at test case level like this

Expand All @@ -395,7 +396,7 @@ Tip: you can do this at test case level like this
super().setUpClass()
cls.env = cls.env(context=dict(
cls.env.context,
test_queue_job_no_delay=True, # no jobs thanks
queue_job__no_delay=True, # no jobs thanks
))

Then all your tests execute the job methods synchronously
Expand Down
1 change: 1 addition & 0 deletions queue_job/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import controllers
from . import fields
from . import models
from . import wizards
from . import jobrunner
from .hooks.post_init_hook import post_init_hook
49 changes: 28 additions & 21 deletions queue_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)


{'name': 'Job Queue',
'version': '12.0.4.1.0',
'author': 'Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/queue',
'license': 'LGPL-3',
'category': 'Generic Modules',
'depends': ['mail'],
'external_dependencies': {'python': ['requests'
],
},
'data': ['security/security.xml',
'security/ir.model.access.csv',
'views/queue_job_views.xml',
'views/queue_job_assets.xml',
'data/queue_data.xml',
"data/queue_job_function_data.xml"],
'installable': True,
'development_status': 'Mature',
'maintainers': ['guewen'],
'post_init_hook': 'post_init_hook'
}
{
"name": "Job Queue",
"version": "12.0.4.1.0",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"license": "LGPL-3",
"category": "Generic Modules",
"depends": ["mail"],
"external_dependencies": {"python": ["requests"]},
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"views/queue_job_assets.xml",
"views/queue_job_views.xml",
"views/queue_job_channel_views.xml",
"views/queue_job_function_views.xml",
"wizards/queue_jobs_to_done_views.xml",
"wizards/queue_requeue_job_views.xml",
"wizards/queue_jobs_to_cancelled_views.xml",
"views/queue_job_menus.xml",
"data/queue_data.xml",
"data/queue_job_function_data.xml",
],
"installable": True,
"development_status": "Mature",
"maintainers": ["guewen"],
"post_init_hook": "post_init_hook",
}
15 changes: 3 additions & 12 deletions queue_job/delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import itertools
import logging
import os
import uuid

from collections import defaultdict, deque

from .job import Job
from .utils import must_run_without_delay

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -219,18 +219,9 @@ def _has_to_execute_directly(self, vertices):
In tests, prefer to use
:func:`odoo.addons.queue_job.tests.common.trap_jobs`.
"""
if os.getenv('TEST_QUEUE_JOB_NO_DELAY'):
_logger.warn(
'`TEST_QUEUE_JOB_NO_DELAY` env var found. NO JOB scheduled.'
)
return True
envs = set(vertex.recordset.env for vertex in vertices)
envs = {vertex.recordset.env for vertex in vertices}
for env in envs:
if env.context.get('test_queue_job_no_delay'):
_logger.warn(
'`test_queue_job_no_delay` ctx key found.'
' NO JOB scheduled.'
)
if must_run_without_delay(env):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion queue_job/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RetryableJobError(JobError):
"""

def __init__(self, msg, seconds=None, ignore_retry=False):
super(RetryableJobError, self).__init__(msg)
super().__init__(msg)
self.seconds = seconds
self.ignore_retry = ignore_retry

Expand Down
6 changes: 2 additions & 4 deletions queue_job/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ class JobDecoder(json.JSONDecoder):
"""Decode json, recomposing recordsets"""

def __init__(self, *args, **kwargs):
env = kwargs.pop('env')
super(JobDecoder, self).__init__(
object_hook=self.object_hook, *args, **kwargs
)
env = kwargs.pop("env")
super().__init__(object_hook=self.object_hook, *args, **kwargs)
assert env
self.env = env

Expand Down
4 changes: 2 additions & 2 deletions queue_job/jobrunner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class WorkerJobRunner(server.Worker):
""" Jobrunner workers """

def __init__(self, multi):
super(WorkerJobRunner, self).__init__(multi)
super().__init__(multi)
self.watchdog_timeout = None
self.runner = QueueJobRunner.from_environ_or_config()

Expand All @@ -59,7 +59,7 @@ def sleep(self):

def signal_handler(self, sig, frame):
_logger.debug("WorkerJobRunner (%s) received signal %s", self.pid, sig)
super(WorkerJobRunner, self).signal_handler(sig, frame)
super().signal_handler(sig, frame)
self.runner.stop()

def process_work(self):
Expand Down
2 changes: 1 addition & 1 deletion queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class SafeSet(set):
def remove(self, o):
# pylint: disable=missing-return,except-pass
try:
super(SafeSet, self).remove(o)
super().remove(o)
except KeyError:
pass

Expand Down
2 changes: 2 additions & 0 deletions queue_job/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from . import base
from . import ir_model_fields
from . import queue_job
from . import queue_job_channel
from . import queue_job_function
4 changes: 2 additions & 2 deletions queue_job/models/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2016 Camptocamp
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

from ..utils import must_run_without_delay
import functools
import inspect
import logging
Expand Down Expand Up @@ -212,8 +213,7 @@ def auto_delay_wrapper(self, *args, **kwargs):
if (
self.env.context.get("job_uuid")
or not context_delay
or self.env.context.get("_job_force_sync")
or self.env.context.get("test_queue_job_no_delay")
or must_run_without_delay(self.env)
):
# we are in the job execution
return auto_delay_wrapper.origin(self, *args, **kwargs)
Expand Down
Loading
Loading