From 68da72542b61ad2b4d84e5325c180db819b81854 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Thu, 18 Apr 2024 09:15:20 -0500 Subject: [PATCH 1/2] bug: Backport to 4.27 --- azure_functions_worker/dispatcher.py | 15 ++++++++++----- azure_functions_worker/loader.py | 4 ++-- .../functions_in_blueprint_only/blueprint.py | 10 ++++++++++ .../test_worker_process_count_functions.py | 8 ++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/azure_functions_worker/dispatcher.py b/azure_functions_worker/dispatcher.py index 2f94e21b..6f96e0ad 100644 --- a/azure_functions_worker/dispatcher.py +++ b/azure_functions_worker/dispatcher.py @@ -344,8 +344,11 @@ def load_function_metadata(self, function_app_directory, caller_info): function_path = os.path.join(function_app_directory, script_file_name) + # For V1, the function path will not exist and + # return None. self._function_metadata_result = ( - self.index_functions(function_path)) \ + self.index_functions(function_path, + function_app_directory)) \ if os.path.exists(function_path) else None async def _handle__functions_metadata_request(self, request): @@ -400,8 +403,9 @@ async def _handle__function_load_request(self, request): logger.info( 'Received WorkerLoadRequest, request ID %s, function_id: %s,' - 'function_name: %s', - self.request_id, function_id, function_name) + 'function_name: %s, function_app_directory : %s', + self.request_id, function_id, function_name, + function_app_directory) programming_model = "V2" try: @@ -672,7 +676,7 @@ async def _handle__function_environment_reload_request(self, request): request_id=self.request_id, function_environment_reload_response=failure_response) - def index_functions(self, function_path: str): + def index_functions(self, function_path: str, function_dir: str): indexed_functions = loader.index_function_app(function_path) logger.info('Indexed function app and found %s functions', len(indexed_functions)) @@ -680,7 +684,8 @@ def index_functions(self, function_path: str): if indexed_functions: fx_metadata_results = loader.process_indexed_function( self._functions, - indexed_functions) + indexed_functions, + function_dir) indexed_function_logs: List[str] = [] for func in indexed_functions: diff --git a/azure_functions_worker/loader.py b/azure_functions_worker/loader.py index 938fde64..6978ba25 100644 --- a/azure_functions_worker/loader.py +++ b/azure_functions_worker/loader.py @@ -121,7 +121,7 @@ def build_variable_interval_retry(retry, max_retry_count, retry_strategy): def process_indexed_function(functions_registry: functions.Registry, - indexed_functions): + indexed_functions, function_dir): fx_metadata_results = [] for indexed_function in indexed_functions: function_info = functions_registry.add_indexed_function( @@ -134,7 +134,7 @@ def process_indexed_function(functions_registry: functions.Registry, name=function_info.name, function_id=function_info.function_id, managed_dependency_enabled=False, # only enabled for PowerShell - directory=function_info.directory, + directory=function_dir, script_file=indexed_function.function_script_file, entry_point=function_info.name, is_proxy=False, # not supported in V4 diff --git a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py index 78504939..d56519ef 100644 --- a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py +++ b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py @@ -1,4 +1,6 @@ import logging +import time +from datetime import datetime import azure.functions as func @@ -29,3 +31,11 @@ def default_template(req: func.HttpRequest) -> func.HttpResponse: " personalized response.", status_code=200 ) + + +@bp.route(route="http_func") +def http_func(req: func.HttpRequest) -> func.HttpResponse: + time.sleep(1) + + current_time = datetime.now().strftime("%H:%M:%S") + return func.HttpResponse(f"{current_time}") \ No newline at end of file diff --git a/tests/endtoend/test_worker_process_count_functions.py b/tests/endtoend/test_worker_process_count_functions.py index 519d8982..c89df2e6 100644 --- a/tests/endtoend/test_worker_process_count_functions.py +++ b/tests/endtoend/test_worker_process_count_functions.py @@ -68,3 +68,11 @@ class TestWorkerProcessCountStein(TestWorkerProcessCount): def get_script_dir(cls): return testutils.E2E_TESTS_FOLDER / 'http_functions' /\ 'http_functions_stein' + + +class TestWorkerProcessCountWithBlueprintStein(TestWorkerProcessCount): + + @classmethod + def get_script_dir(cls): + return testutils.E2E_TESTS_FOLDER / 'blueprint_functions' /\ + 'functions_in_blueprint_only' From 6c668ddd00c458e3385fd1df7fcb9c56d5cdd657 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Thu, 18 Apr 2024 09:28:15 -0500 Subject: [PATCH 2/2] Linting fix --- .../functions_in_blueprint_only/blueprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py index d56519ef..d232dcea 100644 --- a/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py +++ b/tests/endtoend/blueprint_functions/functions_in_blueprint_only/blueprint.py @@ -38,4 +38,4 @@ def http_func(req: func.HttpRequest) -> func.HttpResponse: time.sleep(1) current_time = datetime.now().strftime("%H:%M:%S") - return func.HttpResponse(f"{current_time}") \ No newline at end of file + return func.HttpResponse(f"{current_time}")