@@ -306,10 +306,10 @@ def validate(name, runtime, runtime_docker, runtime_preinstalled, ros_distro, ro
306
306
if description is not None and not isinstance (description , six .string_types ):
307
307
raise InvalidParameterException ('description must be of type string' )
308
308
309
- def _execute_api (self , url , request_method = HttpMethod .GET , payload = None , retry_limit = 0 ):
309
+ def _execute_api (self , url , request_method = HttpMethod .GET , payload = None , retry_limit = 0 , query = None ):
310
310
headers = create_auth_header (self ._auth_token , self ._project )
311
311
headers ['Content-Type' ] = 'application/json'
312
- rest_client = RestClient (url ).method (request_method ).headers (headers )
312
+ rest_client = RestClient (url ).method (request_method ).headers (headers ). query_param ( query )
313
313
response = rest_client .retry (retry_limit ).execute (payload = payload )
314
314
return response
315
315
@@ -575,13 +575,14 @@ def execute_command(self, command, retry_limit=0):
575
575
raise ValueError ("Job ID not found in the response" )
576
576
return self .fetch_command_result (jid , [self .uuid ], timeout = command .timeout )
577
577
578
- def fetch_command_result (self , jid : str , deviceids : list , timeout : int ):
578
+ def fetch_command_result (self , jid : str , deviceids : list , timeout : int , interval : int = 10 ):
579
579
"""
580
580
Fetch the result of the command execution using the job ID (jid) and the first device ID from the list.
581
581
Args:
582
- jobid (str): The job ID of the executed command.
582
+ jid (str): The job ID of the executed command.
583
583
deviceids (list): A list of device IDs on which the command was executed.
584
584
timeout (int): The maximum time to wait for the result (in seconds). Default is 300 seconds.
585
+ interval (int): time interval for retry
585
586
Returns:
586
587
dict: The result of the command execution.
587
588
Raises:
@@ -591,15 +592,15 @@ def fetch_command_result(self, jid: str, deviceids: list, timeout: int):
591
592
592
593
if not deviceids or not isinstance (deviceids , list ):
593
594
raise ValueError ("Device IDs must be provided as a non-empty list." )
594
- url = self ._device_api_host + DEVICE_COMMAND_API_PATH + "jobid"
595
- payload = {
595
+ url = self ._device_api_host + DEVICE_COMMAND_API_PATH + jid
596
+ query = {
596
597
"jid" : jid ,
597
598
"device_id" : deviceids [0 ]
598
599
}
599
- total_time_waited = 0
600
- wait_interval = 10
601
- while total_time_waited < timeout :
602
- response = self ._execute_api (url , HttpMethod .POST , payload )
600
+ time_elapsed = 0
601
+ wait_interval = interval
602
+ while time_elapsed < timeout :
603
+ response = self ._execute_api (url , HttpMethod .GET , query = query )
603
604
if response .status_code == requests .codes .OK :
604
605
result = get_api_response_data (response )
605
606
return result [deviceids [0 ]]
0 commit comments