diff --git a/src/apis/jina_cloud.py b/src/apis/jina_cloud.py index 5f8543d..9684f9a 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_executor_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..26c5360 100644 --- a/src/options/generate/generator.py +++ b/src/options/generate/generator.py @@ -5,7 +5,7 @@ import shutil from typing import List from src.apis import gpt -from src.apis.jina_cloud import process_error_message, push_executor +from src.apis.jina_cloud import process_error_message, push_executor, is_executor_in_hub from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX_DEBUGGING_ITERATIONS, \ PROBLEMATIC_PACKAGES, EXECUTOR_FILE_NAME, EXECUTOR_FILE_TAG, TEST_EXECUTOR_FILE_NAME, TEST_EXECUTOR_FILE_TAG, \ REQUIREMENTS_FILE_NAME, REQUIREMENTS_FILE_TAG, DOCKER_FILE_NAME, DOCKER_FILE_TAG, UNNECESSARY_PACKAGES @@ -190,6 +190,9 @@ metas: # push the gateway print('Final step...') hubble_log = push_executor(gateway_path) + if not is_executor_in_hub(gateway_name): + raise Exception(f'{microservice_name} not in hub. Hubble logs: {hubble_log}') + def debug_microservice(self, path, microservice_name, num_approach, packages): for i in range(1, MAX_DEBUGGING_ITERATIONS): @@ -205,8 +208,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_executor_in_hub(microservice_name): + print('Successfully build microservice.') + break + else: + raise Exception(f'{microservice_name} not in hub. Hubble logs: {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..0aa6d1b --- /dev/null +++ b/test/test_hub.py @@ -0,0 +1,6 @@ +from src.apis.jina_cloud import is_executor_in_hub + + +def test_is_microservice_in_hub(): + assert is_executor_in_hub('reoihoflsnvoiawejeruhvflsfk') is False + assert is_executor_in_hub('CLIPImageEncoder') is True