48
48
WORKER_STATUS )
49
49
from .utils .executor import get_current_loop , execute_async , run_sync_func
50
50
from .utils .helpers import change_cwd , get_sdk_version , get_worker_metadata
51
- from .utils .tracing import serialize_exception , serialize_exception_as_str
51
+ from .utils .tracing import serialize_exception
52
52
from .utils .validators import validate_script_file_name
53
53
54
54
_metadata_result : Optional [List ] = None
60
60
61
61
62
62
async def worker_init_request (request ):
63
- logger .info ("V2 Library Worker: received WorkerInitRequest,"
64
- "Version %s" , VERSION )
63
+ logger .debug ("V2 Library Worker: received WorkerInitRequest,"
64
+ "Version %s" , VERSION )
65
65
global _host , protos , _function_data_cache_enabled , _metadata_exception
66
66
init_request = request .request .worker_init_request
67
67
host_capabilities = init_request .capabilities
@@ -93,7 +93,7 @@ async def worker_init_request(request):
93
93
# dictionary which will be later used in the invocation request
94
94
load_binding_registry ()
95
95
96
- # Index in init by default
96
+ # Index in init by default. Fail if an exception occurs.
97
97
try :
98
98
load_function_metadata (
99
99
init_request .function_app_directory ,
@@ -105,15 +105,23 @@ async def worker_init_request(request):
105
105
initialize_http_server (_host )
106
106
capabilities [REQUIRES_ROUTE_PARAMETERS ] = TRUE
107
107
except HttpServerInitError as ex :
108
- logger .error ("HTTP server init error has occurred" )
109
- _metadata_exception = ex
108
+ return protos .WorkerInitResponse (
109
+ capabilities = capabilities ,
110
+ worker_metadata = get_worker_metadata (protos ),
111
+ result = protos .StatusResult (
112
+ status = protos .StatusResult .Failure ,
113
+ exception = serialize_exception (
114
+ ex , protos ))
115
+ )
110
116
except Exception as ex :
111
- # This is catching an exception that happens during indexing while the init
112
- # request is still in progress. The proxy worker will do nothing with this,
113
- # but metadata will fail
114
- _metadata_exception = ex
115
- logger .error ("An exception in WorkerInitRequest has occurred: %s" ,
116
- serialize_exception_as_str (ex ))
117
+ return protos .WorkerInitResponse (
118
+ capabilities = capabilities ,
119
+ worker_metadata = get_worker_metadata (protos ),
120
+ result = protos .StatusResult (
121
+ status = protos .StatusResult .Failure ,
122
+ exception = serialize_exception (
123
+ ex , protos ))
124
+ )
117
125
118
126
logger .debug ("Successfully completed WorkerInitRequest" )
119
127
return protos .WorkerInitResponse (
@@ -126,26 +134,17 @@ async def worker_init_request(request):
126
134
# worker_status_request can be done in the proxy worker
127
135
128
136
async def functions_metadata_request (request ):
129
- global protos , _metadata_result , _metadata_exception
137
+ global protos , _metadata_result
130
138
logger .debug ("V2 Library Worker: received WorkerMetadataRequest."
131
- " Metadata Result: %s, Metadata Exception: %s, "
139
+ " Metadata Result: %s,"
132
140
" azure-functions version: %s" ,
133
- _metadata_result , _metadata_exception , get_sdk_version ())
134
-
135
- if _metadata_exception :
136
- return protos .FunctionMetadataResponse (
137
- result = protos .StatusResult (
138
- status = protos .StatusResult .Failure ,
139
- exception = serialize_exception (
140
- _metadata_exception , protos )))
141
+ _metadata_result , get_sdk_version ())
141
142
142
- else :
143
- logger .debug ("Successfully completed WorkerMetadataRequest." )
144
- return protos .FunctionMetadataResponse (
145
- use_default_metadata_indexing = False ,
146
- function_metadata_results = _metadata_result ,
147
- result = protos .StatusResult (
148
- status = protos .StatusResult .Success ))
143
+ return protos .FunctionMetadataResponse (
144
+ use_default_metadata_indexing = False ,
145
+ function_metadata_results = _metadata_result ,
146
+ result = protos .StatusResult (
147
+ status = protos .StatusResult .Success ))
149
148
150
149
151
150
async def function_load_request (request ):
@@ -154,7 +153,6 @@ async def function_load_request(request):
154
153
func_request = request .request .function_load_request
155
154
function_id = func_request .function_id
156
155
157
- logger .debug ("Successfully completed WorkerLoadRequest." )
158
156
return protos .FunctionLoadResponse (
159
157
function_id = function_id ,
160
158
result = protos .StatusResult (
@@ -177,9 +175,9 @@ async def invocation_request(request):
177
175
fi : FunctionInfo = _functions .get_function (
178
176
function_id )
179
177
assert fi is not None
180
- logger .debug ("Function name: %s, Function Type: %s" ,
181
- fi .name ,
182
- ("async" if fi .is_async else "sync" ))
178
+ logger .info ("Function name: %s, Function Type: %s" ,
179
+ fi .name ,
180
+ ("async" if fi .is_async else "sync" ))
183
181
184
182
args = {}
185
183
@@ -295,8 +293,8 @@ async def function_environment_reload_request(request):
295
293
This is called only when placeholder mode is true. On worker restarts
296
294
worker init request will be called directly.
297
295
"""
298
- logger .info ("V2 Library Worker: received WorkerEnvReloadRequest,"
299
- "Version %s" , VERSION )
296
+ logger .debug ("V2 Library Worker: received WorkerEnvReloadRequest,"
297
+ "Version %s" , VERSION )
300
298
global _host , protos , _metadata_exception
301
299
try :
302
300
@@ -349,7 +347,10 @@ async def function_environment_reload_request(request):
349
347
initialize_http_server (_host )
350
348
capabilities [REQUIRES_ROUTE_PARAMETERS ] = TRUE
351
349
except HttpServerInitError as ex :
352
- _metadata_exception = ex
350
+ return protos .FunctionEnvironmentReloadResponse (
351
+ result = protos .StatusResult (
352
+ status = protos .StatusResult .Failure ,
353
+ exception = serialize_exception (ex , protos )))
353
354
354
355
# Change function app directory
355
356
if getattr (func_env_reload_request ,
@@ -365,7 +366,6 @@ async def function_environment_reload_request(request):
365
366
status = protos .StatusResult .Success ))
366
367
367
368
except Exception as ex :
368
- _metadata_exception = ex
369
369
return protos .FunctionEnvironmentReloadResponse (
370
370
result = protos .StatusResult (
371
371
status = protos .StatusResult .Failure ,
@@ -385,7 +385,7 @@ def load_function_metadata(function_app_directory, caller_info):
385
385
default_value = PYTHON_SCRIPT_FILE_NAME_DEFAULT )
386
386
387
387
logger .debug (
388
- 'Received load metadata request from %s, '
388
+ 'Received load_function_metadata request from %s, '
389
389
'script_file_name: %s' ,
390
390
caller_info , script_file_name )
391
391
@@ -406,10 +406,6 @@ def load_function_metadata(function_app_directory, caller_info):
406
406
def index_functions (function_path : str , function_dir : str ):
407
407
global protos
408
408
indexed_functions = index_function_app (function_path )
409
- logger .info (
410
- "Indexed function app and found %s functions" ,
411
- len (indexed_functions )
412
- )
413
409
414
410
if indexed_functions :
415
411
fx__metadata_results , fx_bindings_logs = (
@@ -436,7 +432,8 @@ def index_functions(function_path: str, function_dir: str):
436
432
indexed_function_logs .append (function_log )
437
433
438
434
log_data = {
439
- "message" : "Successfully processed FunctionMetadataRequest" ,
435
+ "message" : "Successfully indexed function app." ,
436
+ "function_count" : len (indexed_functions ),
440
437
"functions" : " " .join (indexed_function_logs ),
441
438
"deferred_bindings_enabled" : _functions .deferred_bindings_enabled (),
442
439
"app_settings" : get_python_appsetting_state ()
0 commit comments