Skip to content

Commit

Permalink
Passthrough timeout param for cli lib (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-funk authored Oct 29, 2023
1 parent 006e402 commit 7418f6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions libraries/RW/CLI/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def execute_command(
request_secrets: list[platform.ShellServiceRequestSecret] = None,
env: dict = None,
files: dict = None,
timeout_seconds: int = 60,
) -> platform.ShellServiceResponse:
"""Handle split between shellservice command and local process discretely.
If the user provides a service, use the traditional shellservice flow.
Expand All @@ -60,10 +61,17 @@ def execute_command(
ShellServiceResponse: _description_
"""
if not service:
return execute_local_command(cmd=cmd, request_secrets=request_secrets, env=env, files=files)
return execute_local_command(
cmd=cmd, request_secrets=request_secrets, env=env, files=files, timeout_seconds=timeout_seconds
)
else:
return platform.execute_shell_command(
cmd=cmd, service=service, request_secrets=request_secrets, env=env, files=files
cmd=cmd,
service=service,
request_secrets=request_secrets,
env=env,
files=files,
timeout_seconds=timeout_seconds,
)


Expand Down Expand Up @@ -128,6 +136,7 @@ def run_bash_file(
env: dict = None,
include_in_history: bool = True,
cmd_overide: str = "",
timeout_seconds: int = 60,
**kwargs,
) -> platform.ShellServiceResponse:
"""Runs a bash file from the local file system or remotely on a shellservice.
Expand Down Expand Up @@ -185,6 +194,7 @@ def run_bash_file(
service=target_service,
request_secrets=request_secrets,
env=env,
timeout_seconds=timeout_seconds,
)
if include_in_history:
SHELL_HISTORY.append(file_contents)
Expand All @@ -206,6 +216,7 @@ def run_cli(
optional_namespace: str = "",
optional_context: str = "",
include_in_history: bool = True,
timeout_seconds: int = 60,
**kwargs,
) -> platform.ShellServiceResponse:
"""Executes a string of shell commands either locally or remotely on a shellservice.
Expand Down Expand Up @@ -252,7 +263,13 @@ def run_cli(
if loop_with_items and len(loop_with_items) > 0:
for item in loop_with_items:
cmd = cmd.format(item=item)
iter_rsp = execute_command(cmd=cmd, service=target_service, request_secrets=request_secrets, env=env)
iter_rsp = execute_command(
cmd=cmd,
service=target_service,
request_secrets=request_secrets,
env=env,
timeout_seconds=timeout_seconds,
)
if include_in_history:
SHELL_HISTORY.append(cmd)
looped_results.append(iter_rsp.stdout)
Expand All @@ -271,7 +288,9 @@ def run_cli(
errors=rsp.errors,
)
else:
rsp = execute_command(cmd=cmd, service=target_service, request_secrets=request_secrets, env=env)
rsp = execute_command(
cmd=cmd, service=target_service, request_secrets=request_secrets, env=env, timeout_seconds=timeout_seconds
)
if include_in_history:
SHELL_HISTORY.append(cmd)
logger.info(f"shell stdout: {rsp.stdout}")
Expand Down
2 changes: 1 addition & 1 deletion libraries/RW/CLI/local_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def execute_local_command(
request_secrets: list[platform.ShellServiceRequestSecret] = [],
env: dict = {},
files: dict = {},
timeout_seconds: int = 30,
timeout_seconds: int = 60,
):
USER_ENV: str = os.getenv("USER", None)
# logging.info(f"Local process user detected as: {USER_ENV}")
Expand Down

0 comments on commit 7418f6c

Please sign in to comment.