From 4164faf415ef4c9c1b5c6eec8ae548e338220886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ho=CC=88nicke?= Date: Tue, 25 Apr 2023 15:15:50 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=A9=20fix:=20fail=20fast=20bad=20executor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/jina_cloud.py | 8 ++++++++ src/options/generate/generator.py | 10 ++++++++-- test/test_hub.py | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/test_hub.py diff --git a/src/apis/jina_cloud.py b/src/apis/jina_cloud.py index 5f8543d..3b6d6ff 100644 --- a/src/apis/jina_cloud.py +++ b/src/apis/jina_cloud.py @@ -131,6 +131,14 @@ def _push_executor(dir_path): responses.append(d) return '\n'.join(responses) +def is_microservice_in_hub(microservice_name): + url = f'https://api.hubble.jina.ai/v2/rpc/executor.list?search={microservice_name}&withAnonymous=true' + resp = requests.get(url) + executor_list = resp.json()['data'] + for executor in executor_list: + if 'name' in executor and executor['name'] == microservice_name: + return True + return False def get_user_name(token=None): client = hubble.Client(max_retries=None, jsonify=True, token=token) diff --git a/src/options/generate/generator.py b/src/options/generate/generator.py index e7d5489..aae6bf2 100644 --- a/src/options/generate/generator.py +++ b/src/options/generate/generator.py @@ -205,8 +205,14 @@ metas: if i == MAX_DEBUGGING_ITERATIONS - 1: raise self.MaxDebugTimeReachedException('Could not debug the microservice.') else: - print('Successfully build microservice.') - break + # at the moment, there can be cases where no error log is extracted but the executor is still not published + # it leads to problems later on when someone tries a run or deployment + if is_microservice_in_hub(microservice_name): + print('Successfully build microservice.') + break + else: + raise Exception(log_hubble) + return get_microservice_path(path, microservice_name, packages, num_approach, i) diff --git a/test/test_hub.py b/test/test_hub.py new file mode 100644 index 0000000..a2f1421 --- /dev/null +++ b/test/test_hub.py @@ -0,0 +1,6 @@ +from src.apis.jina_cloud import is_microservice_in_hub + + +def test_is_microservice_in_hub(): + assert is_microservice_in_hub('reoihoflsnvoiawejeruhvflsfk') is False + assert is_microservice_in_hub('CLIPImageEncoder') is True