Skip to content
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
2 changes: 1 addition & 1 deletion taskiq/cli/worker/process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def start(self) -> int | None: # noqa: C901
# We bulk_process all pending events.
while not self.action_queue.empty():
action = self.action_queue.get()
logging.debug("Got event: %s", action)
logger.debug("Got event: %s", action)
if isinstance(action, ReloadAllAction):
action.handle(
workers_num=len(self.workers),
Expand Down
2 changes: 1 addition & 1 deletion taskiq/cli/worker/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def run_worker(args: WorkerArgs) -> int | None:
observer = Observer()
observer.start()
args.workers = 1
logging.warning(
logger.warning(
"Reload on change enabled. Number of worker processes set to 1.",
)

Expand Down
51 changes: 51 additions & 0 deletions tests/cli/worker/test_worker_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,54 @@ def test_worker_process_logs_listening_started(
assert wait_for_output(process, "Listening started.")
finally:
stop(process)


@pytest.mark.parametrize("reload", [False, True])
@pytest.mark.parametrize("configure_logging", [False, True])
def test_reload_respects_logging_configuration(
reload: bool,
configure_logging: bool,
) -> None:
process = subprocess.run( # noqa: S603
[
sys.executable,
"-c",
"""
import logging
import sys
from unittest.mock import patch

from taskiq.cli.worker.args import WorkerArgs
from taskiq.cli.worker.process_manager import ShutdownAction
from taskiq.cli.worker.run import run_worker

reload = sys.argv[1] == "True"
configure_logging = sys.argv[2] == "True"
assert not logging.getLogger().handlers
with (
patch(
"taskiq.cli.worker.process_manager.ProcessManager.prepare_workers",
autospec=True,
) as prepare_workers,
patch("taskiq.cli.worker.run.Observer"),
):
prepare_workers.side_effect = lambda manager: manager.action_queue.put(
ShutdownAction(),
)
run_worker(WorkerArgs(
broker="unused:broker",
modules=[],
reload=reload,
configure_logging=configure_logging,
))
assert bool(logging.getLogger().handlers) == configure_logging
""",
str(reload),
str(configure_logging),
],
capture_output=True,
text=True,
timeout=STARTUP_TIMEOUT,
check=False,
)
assert process.returncode == 0, process.stderr
Loading