Skip to content

Commit

Permalink
chore: add interval as a parameter to the fetch-command-result fucntion
Browse files Browse the repository at this point in the history
  • Loading branch information
rrkumarshikhar committed Oct 16, 2024
1 parent 597bf8c commit 39d9033
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rapyuta_io/clients/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def execute_command(self, command, retry_limit=0):
raise ValueError("Job ID not found in the response")
return self.fetch_command_result(jid, [self.uuid], timeout=command.timeout)

def fetch_command_result(self, jid: str, deviceids: list, timeout: int):
def fetch_command_result(self, jid: str, deviceids: list, timeout: int, interval: int = 10):
"""
Fetch the result of the command execution using the job ID (jid) and the first device ID from the list.
Args:
Expand All @@ -592,15 +592,15 @@ def fetch_command_result(self, jid: str, deviceids: list, timeout: int):
"jid": jid,
"device_id": deviceids[0]
}
total_time_waited = 0
wait_interval = 10
while total_time_waited < timeout:
time_elapsed = 0
wait_interval = interval
while time_elapsed < timeout:
response = self._execute_api(url, HttpMethod.POST, payload)
if response.status_code == requests.codes.OK:
result = get_api_response_data(response)
return result[deviceids[0]]
sleep(wait_interval)
total_time_waited += wait_interval
time_elapsed += wait_interval
raise TimeoutError(f"Command result not available after {timeout} seconds")

def get_config_variables(self):
Expand Down

0 comments on commit 39d9033

Please sign in to comment.