Skip to content

Commit b31f429

Browse files
committed
feat: add ability to specify the default WorkerArgs when parsing from the command line using the WorkerArgs.from_cli() method.
1 parent 7c92e16 commit b31f429

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

taskiq/cli/worker/args.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
1+
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
22
from dataclasses import dataclass, field
3-
from typing import List, Optional, Sequence, Tuple
3+
from typing import Any, Dict, List, Optional, Sequence, Tuple
44

55
from taskiq.acks import AcknowledgeType
66
from taskiq.cli.common_args import LogLevel
@@ -58,11 +58,13 @@ class WorkerArgs:
5858
def from_cli(
5959
cls,
6060
args: Optional[Sequence[str]] = None,
61+
defaults: Optional[Dict[str, Any]] = None,
6162
) -> "WorkerArgs":
6263
"""
6364
Construct TaskiqArgs instanc from CLI arguments.
6465
6566
:param args: list of args as for cli.
67+
:param defaults: default worker arguments.
6668
:return: TaskiqArgs instance.
6769
"""
6870
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
@@ -267,7 +269,10 @@ def from_cli(
267269
help="Maximum number of processes in process pool.",
268270
)
269271

270-
namespace = parser.parse_args(args)
272+
namespace = parser.parse_args(
273+
args,
274+
namespace=None if defaults is None else Namespace(**defaults),
275+
)
271276
# If there are any patterns specified, remove default.
272277
# This is an argparse limitation.
273278
if len(namespace.tasks_pattern) > 1:

0 commit comments

Comments
 (0)