From 544253e545287fc54c5b1612d542e78283bc5934 Mon Sep 17 00:00:00 2001 From: Miikka Kallio Date: Thu, 13 Jul 2023 14:15:58 +0300 Subject: [PATCH 1/2] Fix lambdas. Changed python runtime in lambda.tf from 3.8 to 3.10. Cleaned up lipas_loader.py code. --- .../lambda_functions/lipas_loader/lipas_loader.py | 7 +++---- backend/test/test_services.py | 1 + infra/lambda.tf | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/lambda_functions/lipas_loader/lipas_loader.py b/backend/lambda_functions/lipas_loader/lipas_loader.py index 12a3755..f92c495 100644 --- a/backend/lambda_functions/lipas_loader/lipas_loader.py +++ b/backend/lambda_functions/lipas_loader/lipas_loader.py @@ -50,7 +50,6 @@ def __init__( **kwargs, ) -> None: super().__init__(connection_string, **kwargs) - self.feature_counter: int = 0 # Sorry but this had to be done :-) self.type_codes_all_year = ( type_codes_all_year @@ -87,6 +86,7 @@ def get_features(self, only_page: Optional[int] = None) -> List[int]: # type: i r = requests.get(url, params=params, headers=self.HEADERS) r.raise_for_status() data = r.json() + if data: ids += [item[ID_FIELD] for item in data if "location" in item] current_page += 1 @@ -160,8 +160,7 @@ def get_feature(self, sports_place_id: int): # type: ignore[override] "deleted": False, "tarmo_category": tarmo_category, } - # LOGGER.info(f"Features loaded: {len(flattened)}") - self.feature_counter = self.feature_counter + 1 + # LOGGER.info(f"Features loaded: {len(flattened)}") return flattened def save_feature(self, sport_place: Dict[str, Any], session: Session) -> bool: @@ -219,7 +218,7 @@ def _sport_places_url_and_params(self, page: int) -> Tuple[str, Dict[str, Any]]: return main_url, params def _sport_place_url(self, sports_place_id: int): - # print(self.api_url) + print(self.api_url) return "/".join((self.api_url, LipasLoader.SPORT_PLACES, str(sports_place_id))) diff --git a/backend/test/test_services.py b/backend/test/test_services.py index dccbc9f..40615c0 100644 --- a/backend/test/test_services.py +++ b/backend/test/test_services.py @@ -71,6 +71,7 @@ def populate_two_pages_of_lipas(create_db, main_db_params, lipas_loader_url): payload = { "pages": [1, 2], } + print(payload["pages"][1]) r = requests.post(lipas_loader_url, data=json.dumps(payload)) data = r.json() print(data) diff --git a/infra/lambda.tf b/infra/lambda.tf index d421ba5..7c9d18a 100644 --- a/infra/lambda.tf +++ b/infra/lambda.tf @@ -1,7 +1,7 @@ resource "aws_lambda_function" "db_manager" { function_name = "${var.prefix}-db_manager" filename = "../backend/lambda_functions/db_manager.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "db_manager.handler" memory_size = 128 timeout = 120 @@ -31,7 +31,7 @@ resource "aws_lambda_function" "db_manager" { resource "aws_lambda_function" "lipas_loader" { function_name = "${var.prefix}-lipas_loader" filename = "../backend/lambda_functions/lipas_loader.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "app.lipas_loader.handler" memory_size = 128 timeout = 900 @@ -64,7 +64,7 @@ resource "aws_lambda_permission" "cloudwatch_call_lipas_loader" { resource "aws_lambda_function" "osm_loader" { function_name = "${var.prefix}-osm_loader" filename = "../backend/lambda_functions/osm_loader.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "app.osm_loader.handler" memory_size = 256 timeout = 900 @@ -97,7 +97,7 @@ resource "aws_lambda_permission" "cloudwatch_call_osm_loader" { resource "aws_lambda_function" "wfs_loader" { function_name = "${var.prefix}-wfs_loader" filename = "../backend/lambda_functions/wfs_loader.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "app.wfs_loader.handler" memory_size = 128 timeout = 900 @@ -130,7 +130,7 @@ resource "aws_lambda_permission" "cloudwatch_call_wfs_loader" { resource "aws_lambda_function" "arcgis_loader" { function_name = "${var.prefix}-arcgis_loader" filename = "../backend/lambda_functions/arcgis_loader.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "app.arcgis_loader.handler" memory_size = 256 timeout = 900 @@ -164,7 +164,7 @@ resource "aws_lambda_function" "notifier" { count = var.SLACK_HOOK_URL == "" ? 0 : 1 function_name = "${var.prefix}-notifier" filename = "../backend/lambda_functions/notifier.zip" - runtime = "python3.8" + runtime = "python3.10" handler = "app.notifier.handler" memory_size = 128 timeout = 900 From 948852e8ffdff8104967546c05b9a5f97818f905 Mon Sep 17 00:00:00 2001 From: Miikka Kallio Date: Thu, 13 Jul 2023 14:27:21 +0300 Subject: [PATCH 2/2] Clean up Remove redundant print from test_services.py. --- backend/test/test_services.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/test/test_services.py b/backend/test/test_services.py index 40615c0..dccbc9f 100644 --- a/backend/test/test_services.py +++ b/backend/test/test_services.py @@ -71,7 +71,6 @@ def populate_two_pages_of_lipas(create_db, main_db_params, lipas_loader_url): payload = { "pages": [1, 2], } - print(payload["pages"][1]) r = requests.post(lipas_loader_url, data=json.dumps(payload)) data = r.json() print(data)