From b844a57a78df9d059a4b0bfd3cbdf8bba44dc724 Mon Sep 17 00:00:00 2001 From: Pelayo Torres Date: Thu, 19 Sep 2024 16:37:34 +0200 Subject: [PATCH] Api status logic --- .../core/serviceapidescriptions.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index f32b7b2c..9d73d37b 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -116,8 +116,14 @@ class PublishServiceOperations(Resource): if res.status_code == 201: current_app.logger.info("Service published") - RedisEvent("SERVICE_API_AVAILABLE", "apiIds", - [str(api_id)]).send_event() + if serviceapidescription.api_status is None or len(serviceapidescription.api_status.aef_ids) > 0: + current_app.logger.info("Service available") + RedisEvent("SERVICE_API_AVAILABLE", "apiIds", + [str(api_id)]).send_event() + else: + current_app.logger.info("Service unavailable") + RedisEvent("SERVICE_API_UNAVAILABLE", "apiIds", + [str(api_id)]).send_event() return res except Exception as e: @@ -226,13 +232,25 @@ class PublishServiceOperations(Resource): result = clean_empty(result) current_app.logger.debug("Updated service api") + service_api_description_updated = dict_to_camel_case(result) response = make_response( object=service_api_description_updated, status=200) + if response.status_code == 200: RedisEvent("SERVICE_API_UPDATE", "serviceAPIDescriptions", [ service_api_description_updated]).send_event() + if "apiStatus" not in service_api_description_updated or len(service_api_description_updated["apiStatus"]["aefIds"]) > 0: + current_app.logger.info("Service available") + RedisEvent("SERVICE_API_AVAILABLE", "apiIds", + [str(service_api_id)]).send_event() + else: + current_app.logger.info("Service unavailable") + RedisEvent("SERVICE_API_UNAVAILABLE", "apiIds", + [str(service_api_id)]).send_event() + + return response except Exception as e: -- GitLab