From 79b9134c403b9c1f9db560bcbca245508078c831 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 18 Dec 2020 17:44:31 +0100 Subject: [PATCH] Extract method for checking connection and version from python. --- .../GrpcInterface/Python/rips/instance.py | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/ApplicationCode/GrpcInterface/Python/rips/instance.py b/ApplicationCode/GrpcInterface/Python/rips/instance.py index 601a687cb1..d7081bced7 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/instance.py +++ b/ApplicationCode/GrpcInterface/Python/rips/instance.py @@ -182,6 +182,28 @@ class Instance: # Main version check package self.app = App_pb2_grpc.AppStub(self.channel) + self._check_connection_and_version(self.channel, launched) + + # Intercept UNAVAILABLE errors and retry on failures + interceptors = ( + RetryOnRpcErrorClientInterceptor( + retry_policy=ExponentialBackoffRetryPolicy(min_backoff=100, max_backoff=5000, max_num_retries=20), + status_for_retry=(grpc.StatusCode.UNAVAILABLE,), + ), + ) + + intercepted_channel = grpc.intercept_channel(self.channel, *interceptors) + + # Recreate ommand stubs with the retry policy + self.commands = Commands_pb2_grpc.CommandsStub(intercepted_channel) + + # Service packages + self.project = Project.create(intercepted_channel) + + path = os.getcwd() + self.set_start_dir(path=path) + + def _check_connection_and_version(self, channel, launched): connection_ok = False version_ok = False @@ -206,25 +228,6 @@ class Instance: self.version_string(), " ", self.client_version_string()) - # Intercept UNAVAILABLE errors and retry on failures - interceptors = ( - RetryOnRpcErrorClientInterceptor( - retry_policy=ExponentialBackoffRetryPolicy(min_backoff=100, max_backoff=5000, max_num_retries=20), - status_for_retry=(grpc.StatusCode.UNAVAILABLE,), - ), - ) - - intercepted_channel = grpc.intercept_channel(self.channel, *interceptors) - - # Recreate ommand stubs with the retry policy - self.commands = Commands_pb2_grpc.CommandsStub(intercepted_channel) - - # Service packages - self.project = Project.create(intercepted_channel) - - path = os.getcwd() - self.set_start_dir(path=path) - def __version_message(self): return self.app.GetVersion(Empty())