Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam/max run time #3008

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ def setup_parser_arguments(parser):
help="Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with --headless or --autostart. Defaults to run forever.",
env_var="LOCUST_RUN_TIME",
)
parser.add_argument(
"--max-run-time",
metavar="<time string>",
help="Maximum allowed run time that caps or overrides the --run-time setting. Accepts the same formats as run-time, e.g. (300s, 20m, 3h, 1h30m, etc.).",
env_var="LOCUST_MAX_RUN_TIME",
)
parser.add_argument(
"-l",
"--list",
Expand Down
16 changes: 16 additions & 0 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,22 @@ def ensure_user_class_name(config):
)
sys.exit(1)

if options.max_run_time:
if options.worker:
logger.info("--max-run-time specified for a worker node will be ignored.")
try:
options.max_run_time = parse_timespan(options.max_run_time)
except ValueError:
logger.error(
f"Invalid --max-run-time argument ({options.max_run_time}), accepted formats are for example 120, 120s, 2m, 3h, 3h30m10s."
)
sys.exit(1)
if options.run_time is None or options.max_run_time < options.run_time:
logger.info(
f"Applying --max-run-time cap: run time reduced from {options.run_time if options.run_time else 'undefined'} to {options.max_run_time}."
)
options.run_time = options.max_run_time

if options.csv_prefix:
base_csv_file = os.path.basename(options.csv_prefix)
base_csv_dir = options.csv_prefix[: -len(base_csv_file)]
Expand Down
Loading