Skip to content

Commit f8d473d

Browse files
committed
✨ feat: add run_async behaviour for device
1 parent 8f8d563 commit f8d473d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ sdk_test/package_info.json
1515
config.json
1616
venv/
1717
htmlcov/
18+
ignore
19+
.vscode

rapyuta_io/clients/device.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,9 @@ def execute_command(self, command, retry_limit=0):
568568
if response.status_code == requests.codes.BAD_REQUEST:
569569
raise ParameterMissingException(get_error(response.text))
570570
execution_result = get_api_response_data(response)
571-
if not command.bg:
572-
return execution_result[self.uuid]
571+
if not command.run_async:
572+
return execution_result
573+
573574
jid = execution_result.get('jid')
574575
if not jid:
575576
raise ValueError("Job ID not found in the response")

rapyuta_io/clients/device_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def execute_command(
178178

179179
execution_result = get_api_response_data(response)
180180

181-
if not command.bg:
181+
if not command.run_async:
182182
return execution_result
183183

184184
jid = execution_result.get('jid')

rapyuta_io/clients/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Command(ObjDict):
5252
:ivar shell: Represents the shell where it is going to execute
5353
:ivar env: List of environment variables.
5454
:ivar bg: Boolean value specifying whether the execution runs on the background or not
55+
:ivar run_async: Boolean value to specify to run command in async mode i.e., to run command and return its jid (not depending on completion of the command).
5556
:ivar runas: Run the command as a specific user
5657
:ivar cmd: Command to execute on the device
5758
:ivar pwd: Present working directory
@@ -61,14 +62,15 @@ class Command(ObjDict):
6162
6263
"""
6364

64-
def __init__(self, cmd, shell=None, env=None, bg=False, runas=None, pwd=None, cwd=None, timeout=300):
65+
def __init__(self, cmd, shell=None, env=None, bg=False, run_async=False, runas=None, pwd=None, cwd=None, timeout=300):
6566
super(ObjDict, self).__init__()
6667
if env is None:
6768
env = dict()
6869
self.cmd = cmd
6970
self.shell = shell
7071
self.env = env
7172
self.bg = bg
73+
self.run_async = run_async
7274
self.runas = runas
7375
self.cwd = pwd
7476
if cwd is not None:
@@ -83,6 +85,8 @@ def validate(self):
8385
raise InvalidCommandException("Invalid shell")
8486
if self.bg is not None and not isinstance(self.bg, bool):
8587
raise InvalidCommandException("Invalid background option")
88+
if self.run_async is not None and not isinstance(self.run_async, bool):
89+
raise InvalidCommandException("Invalid run asynchronous option")
8690
if self.runas is not None and not isinstance(self.runas, six.string_types):
8791
raise InvalidCommandException("Invalid runas option")
8892
if self.cwd is not None and not isinstance(self.cwd, six.string_types):

0 commit comments

Comments
 (0)