Skip to content

fix: Update function directory in load request to use /home/site/wwwroot #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions azure_functions_worker/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,12 @@ def load_function_metadata(self, function_app_directory, caller_info):
function_path = os.path.join(function_app_directory,
script_file_name)

self._function_metadata_result = (
self.index_functions(function_path)) \
if os.path.exists(function_path) else None
if not os.path.exists(function_path):
raise FileNotFoundError("function_app.py not "
f"found in {function_path}")

self._function_metadata_result = self.index_functions(
function_path, function_app_directory)

async def _handle__functions_metadata_request(self, request):
metadata_request = request.functions_metadata_request
Expand Down Expand Up @@ -439,8 +442,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:
Expand Down Expand Up @@ -749,7 +753,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",
Expand All @@ -760,7 +764,8 @@ def index_functions(self, function_path: str):
fx_metadata_results, fx_bindings_logs = (
loader.process_indexed_function(
self._functions,
indexed_functions))
indexed_functions,
function_dir))

indexed_function_logs: List[str] = []
indexed_function_bindings_logs = []
Expand Down
4 changes: 2 additions & 2 deletions azure_functions_worker/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 is a list of the RpcFunctionMetadata for
all the functions in the particular app.
Expand Down Expand Up @@ -150,7 +150,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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import time
from datetime import datetime

import azure.functions as func

Expand Down Expand Up @@ -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}")
8 changes: 8 additions & 0 deletions tests/endtoend/test_worker_process_count_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
28 changes: 28 additions & 0 deletions tests/unittests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,34 @@ def test_functions_metadata_request_with_indexing_exception(
metadata_response.function_metadata_response.result.status,
protos.StatusResult.Failure)

@patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'false'})
def test_functions_metadata_request_with_filenotfound_exception(self):

request = protos.StreamingMessage(
worker_init_request=protos.WorkerInitRequest(
host_version="2.3.4",
function_app_directory=str(FUNCTION_APP_DIRECTORY)
)
)

metadata_request = protos.StreamingMessage(
functions_metadata_request=protos.FunctionsMetadataRequest(
function_app_directory="NonExistentDirectory"
)
)

self.loop.run_until_complete(
self.dispatcher._handle__worker_init_request(request))

metadata_response = self.loop.run_until_complete(
self.dispatcher._handle__functions_metadata_request(
metadata_request))

self.assertEqual(
metadata_response.function_metadata_response.result.exception.message,
"FileNotFoundError: function_app.py not "
"found in NonExistentDirectory\\function_app.py")

@patch.dict(os.environ, {PYTHON_ENABLE_INIT_INDEXING: 'false'})
def test_dispatcher_indexing_in_load_request(self):
init_request = protos.StreamingMessage(
Expand Down
Loading