Skip to content

Feature request: Add a built in request_timeout CLI option #278

Description

@yankovs

Hey!

A common thing we do for kartons that may hang is to set the task_timeout option in __init__:

from karton.core import Karton

class MyKarton(Karton):
    def __init__(self):
       self.task_timeout = 10 * 60

This works, but it would be cool if karton supported this from cli arguments.

Proposed usage

If my karton has a __main__.py with:

from .my_karton import MyKarton

MyKarton.main()

Then I'd like to be able to run:

python3 -m MyKartonSrc --task_timeout 600

Proposed implementation

Following karton-core's code, I believe the flag should be added here:

karton/karton/core/base.py

Lines 148 to 168 in e48d872

@classmethod
def args_parser(cls) -> argparse.ArgumentParser:
"""
Return ArgumentParser for main() class method.
This method should be overridden and call super methods
if you want to add more arguments.
"""
parser = argparse.ArgumentParser(description=cls.args_description())
parser.add_argument(
"--version", action="version", version=cast(str, cls.version)
)
parser.add_argument("--config-file", help="Alternative configuration path")
parser.add_argument(
"--identity", help="Alternative identity for Karton service"
)
parser.add_argument("--log-level", help="Logging level of Karton logger")
parser.add_argument(
"--debug", help="Enable debugging mode", action="store_true", default=None
)
return parser

And added as well here:

karton/karton/core/base.py

Lines 170 to 186 in e48d872

@classmethod
def config_from_args(cls, config: Config, args: argparse.Namespace) -> None:
"""
Updates configuration with settings from arguments
This method should be overridden and call super methods
if you want to add more arguments.
"""
config.load_from_dict(
{
"karton": {
"identity": args.identity,
"debug": args.debug,
},
"logging": {"level": args.log_level},
}
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions