From 1d3437cc62ab1b1887d80d149f6df08cab49d8bb Mon Sep 17 00:00:00 2001 From: Fliksh Date: Thu, 22 Feb 2024 21:46:09 +0400 Subject: [PATCH] Added loading logging config from file --- poetry.lock | 98 +++++++++++++++++++++++++++++++++++++-- pyproject.toml | 4 ++ taskiq/cli/worker/args.py | 9 ++++ taskiq/cli/worker/run.py | 61 ++++++++++++++++++++---- 4 files changed, 161 insertions(+), 11 deletions(-) diff --git a/poetry.lock b/poetry.lock index 036a979e..b489eaec 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,9 +1,10 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "annotated-types" version = "0.6.0" description = "Reusable constraint types to use with typing.Annotated" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -18,6 +19,7 @@ typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.9\""} name = "anyio" version = "4.0.0" description = "High level compatibility layer for multiple asynchronous event loop implementations" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -39,6 +41,7 @@ trio = ["trio (>=0.22)"] name = "backports-zoneinfo" version = "0.2.1" description = "Backport of the standard library zoneinfo module" +category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -67,6 +70,7 @@ tzdata = ["tzdata"] name = "black" version = "22.12.0" description = "The uncompromising code formatter." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -102,6 +106,7 @@ uvloop = ["uvloop (>=0.15.2)"] name = "cachetools" version = "5.3.1" description = "Extensible memoizing collections and decorators" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -113,6 +118,7 @@ files = [ name = "cbor2" version = "5.4.6" description = "CBOR (de)serializer with extensive tag support" +category = "main" optional = true python-versions = ">=3.7" files = [ @@ -162,6 +168,7 @@ test = ["pytest", "pytest-cov"] name = "cffi" version = "1.16.0" description = "Foreign Function Interface for Python calling C code." +category = "main" optional = true python-versions = ">=3.8" files = [ @@ -226,6 +233,7 @@ pycparser = "*" name = "cfgv" version = "3.4.0" description = "Validate configuration and produce human readable error messages." +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -237,6 +245,7 @@ files = [ name = "chardet" version = "5.2.0" description = "Universal encoding detector for Python 3" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -248,6 +257,7 @@ files = [ name = "click" version = "8.1.7" description = "Composable command line interface toolkit" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -262,6 +272,7 @@ colorama = {version = "*", markers = "platform_system == \"Windows\""} name = "colorama" version = "0.4.6" description = "Cross-platform colored terminal text." +category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" files = [ @@ -273,6 +284,7 @@ files = [ name = "coverage" version = "6.5.0" description = "Code coverage measurement for Python" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -338,6 +350,7 @@ toml = ["tomli"] name = "distlib" version = "0.3.7" description = "Distribution utilities" +category = "dev" optional = false python-versions = "*" files = [ @@ -349,6 +362,7 @@ files = [ name = "exceptiongroup" version = "1.1.3" description = "Backport of PEP 654 (exception groups)" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -363,6 +377,7 @@ test = ["pytest (>=6)"] name = "execnet" version = "2.0.2" description = "execnet: rapid multi-Python deployment" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -377,6 +392,7 @@ testing = ["hatch", "pre-commit", "pytest", "tox"] name = "filelock" version = "3.12.4" description = "A platform independent file lock." +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -393,6 +409,7 @@ typing = ["typing-extensions (>=4.7.1)"] name = "freezegun" version = "1.2.2" description = "Let your Python tests travel through time" +category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -407,6 +424,7 @@ python-dateutil = ">=2.7" name = "gitignore-parser" version = "0.1.9" description = "A spec-compliant gitignore parser for Python 3.5+" +category = "main" optional = true python-versions = "*" files = [ @@ -417,6 +435,7 @@ files = [ name = "graphlib-backport" version = "1.0.3" description = "Backport of the Python 3.9 graphlib module for Python 3.6+" +category = "main" optional = false python-versions = ">=3.6,<4.0" files = [ @@ -428,6 +447,7 @@ files = [ name = "identify" version = "2.5.30" description = "File identification library for Python" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -442,6 +462,7 @@ license = ["ukkonen"] name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" +category = "main" optional = false python-versions = ">=3.5" files = [ @@ -453,6 +474,7 @@ files = [ name = "importlib-metadata" version = "6.8.0" description = "Read metadata from Python packages" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -472,6 +494,7 @@ testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs name = "iniconfig" version = "2.0.0" description = "brain-dead simple config-ini parsing" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -483,6 +506,7 @@ files = [ name = "mock" version = "4.0.3" description = "Rolling backport of unittest.mock for all Pythons" +category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -499,6 +523,7 @@ test = ["pytest (<5.4)", "pytest-cov"] name = "msgpack" version = "1.0.7" description = "MessagePack serializer" +category = "main" optional = true python-versions = ">=3.8" files = [ @@ -564,6 +589,7 @@ files = [ name = "mypy" version = "1.6.1" description = "Optional static typing for Python" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -610,6 +636,7 @@ reports = ["lxml"] name = "mypy-extensions" version = "1.0.0" description = "Type system extensions for programs checked with the mypy type checker." +category = "dev" optional = false python-versions = ">=3.5" files = [ @@ -621,6 +648,7 @@ files = [ name = "nodeenv" version = "1.8.0" description = "Node.js virtual environment builder" +category = "dev" optional = false python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" files = [ @@ -635,6 +663,7 @@ setuptools = "*" name = "orjson" version = "3.9.9" description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy" +category = "main" optional = true python-versions = ">=3.8" files = [ @@ -694,6 +723,7 @@ files = [ name = "packaging" version = "23.2" description = "Core utilities for Python packages" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -705,6 +735,7 @@ files = [ name = "pathspec" version = "0.11.2" description = "Utility library for gitignore style pattern matching of file paths." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -716,6 +747,7 @@ files = [ name = "platformdirs" version = "3.11.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -731,6 +763,7 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-co name = "pluggy" version = "1.3.0" description = "plugin and hook calling mechanisms for python" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -746,6 +779,7 @@ testing = ["pytest", "pytest-benchmark"] name = "pre-commit" version = "2.21.0" description = "A framework for managing and maintaining multi-language pre-commit hooks." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -764,6 +798,7 @@ virtualenv = ">=20.10.0" name = "prometheus-client" version = "0.17.1" description = "Python client for the Prometheus monitoring system." +category = "main" optional = true python-versions = ">=3.6" files = [ @@ -778,6 +813,7 @@ twisted = ["twisted"] name = "psutil" version = "5.9.6" description = "Cross-platform lib for process and system monitoring in Python." +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" files = [ @@ -806,6 +842,7 @@ test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"] name = "py" version = "1.11.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ @@ -817,6 +854,7 @@ files = [ name = "pycparser" version = "2.21" description = "C parser in Python" +category = "main" optional = true python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ @@ -828,6 +866,7 @@ files = [ name = "pycron" version = "3.0.0" description = "Simple cron-like parser, which determines if current datetime matches conditions." +category = "main" optional = false python-versions = ">=3.5" files = [ @@ -838,6 +877,7 @@ files = [ name = "pydantic" version = "2.4.2" description = "Data validation using Python type hints" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -857,6 +897,7 @@ email = ["email-validator (>=2.0.0)"] name = "pydantic-core" version = "2.10.1" description = "" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -975,6 +1016,7 @@ typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" name = "pyproject-api" version = "1.6.1" description = "API to interact with the python pyproject.toml based projects" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -994,6 +1036,7 @@ testing = ["covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytes name = "pytest" version = "7.4.2" description = "pytest: simple powerful testing with Python" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1016,6 +1059,7 @@ testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "no name = "pytest-cov" version = "3.0.0" description = "Pytest plugin for measuring coverage." +category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -1034,6 +1078,7 @@ testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtuale name = "pytest-forked" version = "1.6.0" description = "run tests in isolated forked subprocesses" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1049,6 +1094,7 @@ pytest = ">=3.10" name = "pytest-mock" version = "3.11.1" description = "Thin-wrapper around the mock package for easier use with pytest" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1066,6 +1112,7 @@ dev = ["pre-commit", "pytest-asyncio", "tox"] name = "pytest-xdist" version = "2.5.0" description = "pytest xdist plugin for distributed testing and loop-on-failing modes" +category = "dev" optional = false python-versions = ">=3.6" files = [ @@ -1088,6 +1135,7 @@ testing = ["filelock"] name = "python-dateutil" version = "2.8.2" description = "Extensions to the standard Python datetime module" +category = "dev" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" files = [ @@ -1102,6 +1150,7 @@ six = ">=1.5" name = "pytz" version = "2023.3.post1" description = "World timezone definitions, modern and historical" +category = "main" optional = false python-versions = "*" files = [ @@ -1113,6 +1162,7 @@ files = [ name = "pyyaml" version = "6.0.1" description = "YAML parser and emitter for Python" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -1121,6 +1171,7 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -1128,8 +1179,16 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -1146,6 +1205,7 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -1153,6 +1213,7 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -1162,6 +1223,7 @@ files = [ name = "pyzmq" version = "23.2.1" description = "Python bindings for 0MQ" +category = "main" optional = true python-versions = ">=3.6" files = [ @@ -1249,6 +1311,7 @@ py = {version = "*", markers = "implementation_name == \"pypy\""} name = "ruff" version = "0.0.291" description = "An extremely fast Python linter, written in Rust." +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1275,6 +1338,7 @@ files = [ name = "setuptools" version = "68.2.2" description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1291,6 +1355,7 @@ testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jar name = "six" version = "1.16.0" description = "Python 2 and 3 compatibility utilities" +category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" files = [ @@ -1302,6 +1367,7 @@ files = [ name = "sniffio" version = "1.3.0" description = "Sniff out which async library your code is running under" +category = "main" optional = false python-versions = ">=3.7" files = [ @@ -1313,6 +1379,7 @@ files = [ name = "taskiq-dependencies" version = "1.4.2" description = "FastAPI like dependency injection implementation" +category = "main" optional = false python-versions = ">=3.8.1,<4.0.0" files = [ @@ -1327,6 +1394,7 @@ graphlib-backport = {version = ">=1.0.3,<2.0.0", markers = "python_version < \"3 name = "tomli" version = "2.0.1" description = "A lil' TOML parser" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1338,6 +1406,7 @@ files = [ name = "tox" version = "4.11.3" description = "tox is a generic virtualenv management and test command line tool" +category = "dev" optional = false python-versions = ">=3.8" files = [ @@ -1365,6 +1434,7 @@ testing = ["build[virtualenv] (>=0.10)", "covdefaults (>=2.3)", "detect-test-pol name = "types-mock" version = "4.0.15.2" description = "Typing stubs for mock" +category = "dev" optional = false python-versions = "*" files = [ @@ -1376,6 +1446,7 @@ files = [ name = "types-pytz" version = "2023.3.1.1" description = "Typing stubs for pytz" +category = "dev" optional = false python-versions = "*" files = [ @@ -1383,10 +1454,23 @@ files = [ {file = "types_pytz-2023.3.1.1-py3-none-any.whl", hash = "sha256:1999a123a3dc0e39a2ef6d19f3f8584211de9e6a77fe7a0259f04a524e90a5cf"}, ] +[[package]] +name = "types-pyyaml" +version = "6.0.12.12" +description = "Typing stubs for PyYAML" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "types-PyYAML-6.0.12.12.tar.gz", hash = "sha256:334373d392fde0fdf95af5c3f1661885fa10c52167b14593eb856289e1855062"}, + {file = "types_PyYAML-6.0.12.12-py3-none-any.whl", hash = "sha256:c05bc6c158facb0676674b7f11fe3960db4f389718e19e62bd2b84d6205cfd24"}, +] + [[package]] name = "types-tzlocal" version = "5.1.0.0" description = "Typing stubs for tzlocal" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1401,6 +1485,7 @@ types-pytz = "*" name = "typing-extensions" version = "4.8.0" description = "Backported and Experimental Type Hints for Python 3.8+" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -1412,6 +1497,7 @@ files = [ name = "tzdata" version = "2023.3" description = "Provider of IANA time zone data" +category = "dev" optional = false python-versions = ">=2" files = [ @@ -1423,6 +1509,7 @@ files = [ name = "tzlocal" version = "5.1" description = "tzinfo object for the local timezone" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1441,6 +1528,7 @@ devenv = ["black", "check-manifest", "flake8", "pyroma", "pytest (>=4.3)", "pyte name = "uvloop" version = "0.18.0" description = "Fast implementation of asyncio event loop on top of libuv" +category = "main" optional = true python-versions = ">=3.7.0" files = [ @@ -1490,6 +1578,7 @@ test = ["Cython (>=0.29.36,<0.30.0)", "aiohttp (==3.9.0b0)", "aiohttp (>=3.8.1)" name = "virtualenv" version = "20.24.5" description = "Virtual Python Environment builder" +category = "dev" optional = false python-versions = ">=3.7" files = [ @@ -1510,6 +1599,7 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess name = "watchdog" version = "2.3.1" description = "Filesystem events monitoring" +category = "main" optional = true python-versions = ">=3.6" files = [ @@ -1550,6 +1640,7 @@ watchmedo = ["PyYAML (>=3.10)"] name = "zipp" version = "3.17.0" description = "Backport of pathlib-compatible object wrapper for zip files" +category = "main" optional = false python-versions = ">=3.8" files = [ @@ -1566,11 +1657,12 @@ cbor = ["cbor2"] metrics = ["prometheus_client"] msgpack = ["msgpack"] orjson = ["orjson"] -reload = ["gitignore-parser", "watchdog"] +pyyaml = ["pyyaml"] +reload = ["watchdog", "gitignore-parser"] uv = ["uvloop"] zmq = ["pyzmq"] [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "d324e106ec5335886db06fbe8b91aabdc7ffa8547bc075a3c4e7275f1be8d4c7" +content-hash = "545905cd82c9ad546405e0ae05b29798639976f14772620f068963d299e3127d" diff --git a/pyproject.toml b/pyproject.toml index 373263e9..08b197ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,8 @@ pytz = "*" orjson = { version = "^3.9.9", optional = true } msgpack = { version = "^1.0.7", optional = true } cbor2 = { version = "^5.4.6", optional = true } +# For load log config from yaml +pyyaml = {version = "^6.0.1", optional = true} [tool.poetry.dev-dependencies] pytest = "^7.1.2" @@ -65,6 +67,7 @@ pytest-mock = "^3.11.1" tzlocal = "^5.0.1" types-tzlocal = "^5.0.1.1" types-pytz = "^2023.3.1.1" +types-pyyaml = "^6.0.12.12" [tool.poetry.extras] zmq = ["pyzmq"] @@ -74,6 +77,7 @@ reload = ["watchdog", "gitignore-parser"] orjson = ["orjson"] msgpack = ["msgpack"] cbor = ["cbor2"] +pyyaml = ["pyyaml"] [tool.poetry.scripts] taskiq = "taskiq.__main__:main" diff --git a/taskiq/cli/worker/args.py b/taskiq/cli/worker/args.py index 4c225b07..04ab38db 100644 --- a/taskiq/cli/worker/args.py +++ b/taskiq/cli/worker/args.py @@ -1,5 +1,6 @@ from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser from dataclasses import dataclass, field +from pathlib import Path from typing import List, Optional, Sequence, Tuple from taskiq.acks import AcknowledgeType @@ -29,6 +30,7 @@ class WorkerArgs: tasks_pattern: Sequence[str] = ("**/tasks.py",) fs_discover: bool = False configure_logging: bool = True + log_config: Optional[Path] = None log_level: LogLevel = LogLevel.INFO workers: int = 2 max_threadpool_threads: int = 10 @@ -183,6 +185,13 @@ def from_cli( dest="configure_logging", help="Use this parameter if your application configures custom logging.", ) + parser.add_argument( + "--log-config", + type=Path, + dest="log_config", + default=None, + help="Configure logging from file.", + ) parser.add_argument( "--max-fails", type=int, diff --git a/taskiq/cli/worker/run.py b/taskiq/cli/worker/run.py index fd253d77..64731534 100644 --- a/taskiq/cli/worker/run.py +++ b/taskiq/cli/worker/run.py @@ -1,8 +1,11 @@ import asyncio +import json import logging +import logging.config import signal from concurrent.futures import ThreadPoolExecutor from multiprocessing import set_start_method +from pathlib import Path from sys import platform from typing import Any, Optional, Type @@ -23,6 +26,12 @@ except ImportError: Observer = None # type: ignore + +try: + import yaml +except ImportError: + yaml = None # type: ignore + logger = logging.getLogger("taskiq.worker") @@ -148,6 +157,49 @@ def interrupt_handler(signum: int, _frame: Any) -> None: loop.run_until_complete(shutdown_broker(broker, args.shutdown_timeout)) +def load_logging_config_file(log_config: Path) -> dict[str, Any]: + """ + This function load logging configuration file to dictionary. + + :param log_config: path to log configuration file. + + :raises ValueError: if file format not supported. + :returns: Dictionary with logging configuration. + """ + with log_config.open("r", encoding="utf-8") as log_config_file: + if log_config.suffix == ".json": + return json.load(log_config_file) + if log_config.suffix in [".yaml", ".yml"]: + if yaml is None: + raise ValueError( + "To use --log-config with yaml, please install taskiq[pyyaml].", + ) + return yaml.safe_load(log_config_file) + raise ValueError("Log config has invalid format.") + + +def configure_logging(args: WorkerArgs) -> None: + """ + This function configure logging. + + :param args: CLI arguments. + """ + if args.log_config is not None: + if args.log_config.suffix == ".ini": + logging.config.fileConfig(args.log_config) + return + logging.config.dictConfig(load_logging_config_file(args.log_config)) + return + if args.configure_logging: + logging.basicConfig( + level=logging.getLevelName(args.log_level), + format="[%(asctime)s][%(name)s][%(levelname)-7s]" + "[%(processName)s] %(message)s", + ) + logging.getLogger("taskiq").setLevel(level=logging.getLevelName(args.log_level)) + logging.getLogger("watchdog.observers.inotify_buffer").setLevel(level=logging.INFO) + + def run_worker(args: WorkerArgs) -> Optional[int]: """ This function starts worker processes. @@ -162,14 +214,7 @@ def run_worker(args: WorkerArgs) -> Optional[int]: """ if platform == "darwin": set_start_method("spawn") - if args.configure_logging: - logging.basicConfig( - level=logging.getLevelName(args.log_level), - format="[%(asctime)s][%(name)s][%(levelname)-7s]" - "[%(processName)s] %(message)s", - ) - logging.getLogger("taskiq").setLevel(level=logging.getLevelName(args.log_level)) - logging.getLogger("watchdog.observers.inotify_buffer").setLevel(level=logging.INFO) + configure_logging(args) logger.info("Starting %s worker processes.", args.workers) observer = None