Skip to content

Commit 6b57608

Browse files
committed
Addressed comments
1 parent c93a1e0 commit 6b57608

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

azure_functions_worker/dispatcher.py

+43-24
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,12 @@ async def _handle__worker_init_request(self, request):
302302
bindings.load_binding_registry()
303303

304304
if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
305-
self.load_function_metadata(
306-
worker_init_request.function_app_directory,
307-
caller_info="worker_init_request")
305+
try:
306+
self.load_function_metadata(
307+
worker_init_request.function_app_directory,
308+
caller_info="worker_init_request")
309+
except Exception as ex:
310+
self._function_metadata_exception = ex
308311

309312
return protos.StreamingMessage(
310313
request_id=self.request_id,
@@ -332,31 +335,41 @@ def load_function_metadata(self, function_app_directory, caller_info):
332335
setting=PYTHON_SCRIPT_FILE_NAME,
333336
default_value=f'{PYTHON_SCRIPT_FILE_NAME_DEFAULT}')
334337

335-
logger.info(
336-
'Received load metadata request from from %s, request ID %s, '
338+
logger.debug(
339+
'Received load metadata request from %s, request ID %s, '
337340
'script_file_name: %s',
338341
caller_info, self.request_id, script_file_name)
339342

340-
try:
341-
validate_script_file_name(script_file_name)
342-
function_path = os.path.join(function_app_directory,
343-
script_file_name)
343+
validate_script_file_name(script_file_name)
344+
function_path = os.path.join(function_app_directory,
345+
script_file_name)
344346

345-
self._function_metadata_result = (
346-
self.index_functions(function_path)) \
347-
if os.path.exists(function_path) else None
348-
349-
except Exception as ex:
350-
self._function_metadata_exception = ex
347+
self._function_metadata_result = (
348+
self.index_functions(function_path)) \
349+
if os.path.exists(function_path) else None
351350

352351
async def _handle__functions_metadata_request(self, request):
353352
metadata_request = request.functions_metadata_request
354353
function_app_directory = metadata_request.function_app_directory
355354

355+
script_file_name = get_app_setting(
356+
setting=PYTHON_SCRIPT_FILE_NAME,
357+
default_value=f'{PYTHON_SCRIPT_FILE_NAME_DEFAULT}')
358+
function_path = os.path.join(function_app_directory,
359+
script_file_name)
360+
361+
logger.info(
362+
'Received WorkerMetadataRequest, request ID %s, '
363+
'function_path: %s',
364+
self.request_id, function_path)
365+
356366
if not is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
357-
self.load_function_metadata(
358-
function_app_directory,
359-
caller_info="functions_metadata_request")
367+
try:
368+
self.load_function_metadata(
369+
function_app_directory,
370+
caller_info="functions_metadata_request")
371+
except Exception as ex:
372+
self._function_metadata_exception = ex
360373

361374
if self._function_metadata_exception:
362375
return protos.StreamingMessage(
@@ -404,9 +417,12 @@ async def _handle__function_load_request(self, request):
404417
# function and update the workers registry
405418

406419
if not is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
407-
self.load_function_metadata(
408-
function_app_directory,
409-
caller_info="functions_load_request")
420+
try:
421+
self.load_function_metadata(
422+
function_app_directory,
423+
caller_info="functions_load_request")
424+
except Exception as ex:
425+
self._function_metadata_exception = ex
410426

411427
# For the second worker, if there was an exception in
412428
# indexing, we raise it here
@@ -626,9 +642,12 @@ async def _handle__function_environment_reload_request(self, request):
626642
bindings.load_binding_registry()
627643

628644
if is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
629-
self.load_function_metadata(
630-
directory,
631-
caller_info="environment_reload_request")
645+
try:
646+
self.load_function_metadata(
647+
directory,
648+
caller_info="environment_reload_request")
649+
except Exception as ex:
650+
self._function_metadata_exception = ex
632651

633652
# Change function app directory
634653
if getattr(func_env_reload_request,

tests/unittests/test_dispatcher.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
PYTHON_THREADPOOL_THREAD_COUNT_MAX_37,
1515
PYTHON_THREADPOOL_THREAD_COUNT_MIN,
1616
PYTHON_ENABLE_INIT_INDEXING,
17-
METADATA_PROPERTIES_WORKER_INDEXED)
17+
METADATA_PROPERTIES_WORKER_INDEXED,
18+
PYTHON_ENABLE_DEBUG_LOGGING)
1819
from azure_functions_worker.dispatcher import Dispatcher
1920
from azure_functions_worker.version import VERSION
2021
from tests.utils import testutils
@@ -691,7 +692,8 @@ async def test_dispatcher_load_azfunc_in_init(self):
691692
async def test_dispatcher_indexing_in_init_request(self):
692693
"""Test if azure functions is loaded during init
693694
"""
694-
env = {PYTHON_ENABLE_INIT_INDEXING: "1"}
695+
env = {PYTHON_ENABLE_INIT_INDEXING: "1",
696+
PYTHON_ENABLE_DEBUG_LOGGING: "1"}
695697
with patch.dict(os.environ, env):
696698
async with self._ctrl as host:
697699
r = await host.init_worker()
@@ -704,7 +706,7 @@ async def test_dispatcher_indexing_in_init_request(self):
704706

705707
self.assertEqual(
706708
len([log for log in r.logs if log.message.startswith(
707-
"Received WorkerMetadataRequest from "
709+
"Received load metadata request from "
708710
"worker_init_request"
709711
)]),
710712
1

0 commit comments

Comments
 (0)