Skip to content

Commit

Permalink
chore: add timeout support in command
Browse files Browse the repository at this point in the history
  • Loading branch information
rrkumarshikhar authored and pallabpain committed Nov 21, 2024
1 parent 867ebe8 commit 6f693c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rapyuta_io/clients/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ def execute_command(self, command, retry_limit=0):
jid = execution_result.get('jid')
if not jid:
raise ValueError("Job ID not found in the response")
return self.fetch_command_result(jid, [self.uuid], timeout=300)
return self.fetch_command_result(jid, [self.uuid], timeout=command.timeout)

def fetch_command_result(self, jid: str, deviceids: list, timeout: int = 300):
def fetch_command_result(self, jid: str, deviceids: list, timeout: int):
"""
Fetch the result of the command execution using the job ID (jid) and the first device ID from the list.
Args:
Expand Down
5 changes: 4 additions & 1 deletion rapyuta_io/clients/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Command(ObjDict):
"""

def __init__(self, cmd, shell=None, env=None, bg=False, runas=None, pwd=None, cwd=None):
def __init__(self, cmd, shell=None, env=None, bg=False, runas=None, pwd=None, cwd=None, timeout=300):
super(ObjDict, self).__init__()
if env is None:
env = dict()
Expand All @@ -73,6 +73,7 @@ def __init__(self, cmd, shell=None, env=None, bg=False, runas=None, pwd=None, cw
self.cwd = pwd
if cwd is not None:
self.cwd = cwd
self.timeout = timeout
self.validate()

def validate(self):
Expand All @@ -93,6 +94,8 @@ def validate(self):
raise InvalidCommandException('Invalid environment variables')
return
raise InvalidCommandException('Invalid environment variables')
if self.timeout <= 0:
raise InvalidCommandException("Invalid timeout value")

def to_json(self):
# TODO: we need to rewrite this function.
Expand Down

0 comments on commit 6f693c3

Please sign in to comment.