Skip to content

Commit 01345cb

Browse files
committed
feat: add run_async behaviour for device
1 parent 8f8d563 commit 01345cb

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,16 @@ def execute_command(self, command, retry_limit=0):
561561
>>> device.execute_command(command)
562562
563563
"""
564+
if command.bg:
565+
command.cmd += ' &'
564566
command.validate()
565567
command.device_ids = [self.uuid]
566568
url = self._device_api_host + DEVICE_COMMAND_API_PATH
567569
response = self._execute_api(url, HttpMethod.POST, command.to_json(), retry_limit)
568570
if response.status_code == requests.codes.BAD_REQUEST:
569571
raise ParameterMissingException(get_error(response.text))
570572
execution_result = get_api_response_data(response)
571-
if not command.bg:
573+
if not command.bg and not command.run_async:
572574
return execution_result[self.uuid]
573575
jid = execution_result.get('jid')
574576
if not jid:

rapyuta_io/clients/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ class Command(ObjDict):
6161
6262
"""
6363

64-
def __init__(self, cmd, shell=None, env=None, bg=False, runas=None, pwd=None, cwd=None, timeout=300):
64+
def __init__(self, cmd, shell=None, env=None, bg=False, run_async=False, runas=None, pwd=None, cwd=None, timeout=300):
6565
super(ObjDict, self).__init__()
6666
if env is None:
6767
env = dict()
6868
self.cmd = cmd
6969
self.shell = shell
7070
self.env = env
7171
self.bg = bg
72+
self.run_async = run_async
7273
self.runas = runas
7374
self.cwd = pwd
7475
if cwd is not None:
@@ -83,6 +84,8 @@ def validate(self):
8384
raise InvalidCommandException("Invalid shell")
8485
if self.bg is not None and not isinstance(self.bg, bool):
8586
raise InvalidCommandException("Invalid background option")
87+
if self.run_async is not None and not isinstance(self.run_async, bool):
88+
raise InvalidCommandException("Invalid run asynchronous option")
8689
if self.runas is not None and not isinstance(self.runas, six.string_types):
8790
raise InvalidCommandException("Invalid runas option")
8891
if self.cwd is not None and not isinstance(self.cwd, six.string_types):

0 commit comments

Comments
 (0)