Skip to content

Commit

Permalink
[IMP] queue_job: Don't raise a warning for valid context
Browse files Browse the repository at this point in the history
As the 'queue_job__no_delay' context key is the valid one to use,
don't raise warnings during tests, but log it as information level.
  • Loading branch information
rousseldenis committed Sep 10, 2024
1 parent 7e5efe7 commit f8d41dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion queue_job/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
import os

from odoo.tools import config

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -36,5 +38,8 @@ def must_run_without_delay(env):
return True

if env.context.get("queue_job__no_delay"):
_logger.warning("`queue_job__no_delay` ctx key found. NO JOB scheduled.")
if config.get("test_enable"):
_logger.info("`queue_job__no_delay` ctx key found. NO JOB scheduled.")
else:
_logger.warning("`queue_job__no_delay` ctx key found. NO JOB scheduled.")

Check warning on line 44 in queue_job/utils.py

View check run for this annotation

Codecov / codecov/patch

queue_job/utils.py#L44

Added line #L44 was not covered by tests
return True
13 changes: 8 additions & 5 deletions test_queue_job/tests/test_job_auto_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ def test_auto_delay_inside_job(self):

def test_auto_delay_force_sync(self):
"""method forced to run synchronously"""
result = (
self.env["test.queue.job"]
.with_context(_job_force_sync=True)
.delay_me(1, kwarg=2)
)
with self.assertLogs(level="WARNING") as log_catcher:
result = (
self.env["test.queue.job"]
.with_context(_job_force_sync=True)
.delay_me(1, kwarg=2)
)
self.assertEqual(len(log_catcher.output), 1, "Exactly one warning should be logged")
self.assertIn(" ctx key found. NO JOB scheduled. ", log_catcher.output[0])
self.assertTrue(result, (1, 2))

def test_auto_delay_context_key_set(self):
Expand Down

0 comments on commit f8d41dd

Please sign in to comment.