@@ -312,30 +312,7 @@ async def _handle__functions_metadata_request(self, request):
312
312
status = protos .StatusResult .Success )))
313
313
314
314
try :
315
- indexed_functions = loader .index_function_app (function_path )
316
- logger .info ('Indexed function app and found %s functions' ,
317
- len (indexed_functions ))
318
-
319
- fx_metadata_results = []
320
- if indexed_functions :
321
- indexed_function_logs : List [str ] = []
322
- for func in indexed_functions :
323
- function_log = "Function Name: {}, Function Binding: {}" \
324
- .format (func .get_function_name (),
325
- [(binding .type , binding .name ) for binding in
326
- func .get_bindings ()])
327
- indexed_function_logs .append (function_log )
328
-
329
- logger .info (
330
- 'Successfully processed FunctionMetadataRequest for '
331
- 'functions: %s' , " " .join (indexed_function_logs ))
332
-
333
- fx_metadata_results = loader .process_indexed_function (
334
- self ._functions ,
335
- indexed_functions )
336
- else :
337
- logger .warning ("No functions indexed. Please refer to "
338
- "aka.ms/pythonprogrammingmodel for more info." )
315
+ fx_metadata_results = self .index_functions (function_path )
339
316
340
317
return protos .StreamingMessage (
341
318
request_id = request .request_id ,
@@ -355,33 +332,48 @@ async def _handle__functions_metadata_request(self, request):
355
332
async def _handle__function_load_request (self , request ):
356
333
func_request = request .function_load_request
357
334
function_id = func_request .function_id
358
- function_name = func_request .metadata .name
335
+ function_metadata = func_request .metadata
336
+ function_name = function_metadata .name
337
+ function_path = os .path .join (function_metadata .directory ,
338
+ SCRIPT_FILE_NAME )
359
339
360
340
logger .info (
361
341
'Received WorkerLoadRequest, request ID %s, function_id: %s,'
362
342
'function_name: %s,' , self .request_id , function_id , function_name )
363
343
364
344
try :
365
345
if not self ._functions .get_function (function_id ):
366
- func = loader .load_function (
367
- func_request .metadata .name ,
368
- func_request .metadata .directory ,
369
- func_request .metadata .script_file ,
370
- func_request .metadata .entry_point )
371
-
372
- self ._functions .add_function (
373
- function_id , func , func_request .metadata )
374
-
375
- ExtensionManager .function_load_extension (
376
- function_name ,
377
- func_request .metadata .directory
378
- )
379
-
380
- logger .info ('Successfully processed FunctionLoadRequest, '
381
- 'request ID: %s, '
382
- 'function ID: %s,'
383
- 'function Name: %s' , self .request_id , function_id ,
384
- function_name )
346
+ if function_metadata .properties .get ("worker_indexed" , False ) \
347
+ or os .path .exists (function_path ):
348
+ # This is for the second worker and above where the worker
349
+ # indexing is enabled and load request is called without
350
+ # calling the metadata request. In this case we index the
351
+ # function and update the workers registry
352
+ logger .info (f"Indexing function { function_name } in the "
353
+ f"load request" )
354
+ _ = self .index_functions (function_path )
355
+ else :
356
+ # legacy function
357
+ func = loader .load_function (
358
+ func_request .metadata .name ,
359
+ func_request .metadata .directory ,
360
+ func_request .metadata .script_file ,
361
+ func_request .metadata .entry_point )
362
+
363
+ self ._functions .add_function (
364
+ function_id , func , func_request .metadata )
365
+
366
+ ExtensionManager .function_load_extension (
367
+ function_name ,
368
+ func_request .metadata .directory
369
+ )
370
+
371
+ logger .info ('Successfully processed FunctionLoadRequest, '
372
+ 'request ID: %s, '
373
+ 'function ID: %s,'
374
+ 'function Name: %s' , self .request_id ,
375
+ function_id ,
376
+ function_name )
385
377
386
378
return protos .StreamingMessage (
387
379
request_id = self .request_id ,
@@ -577,6 +569,30 @@ async def _handle__function_environment_reload_request(self, request):
577
569
request_id = self .request_id ,
578
570
function_environment_reload_response = failure_response )
579
571
572
+ def index_functions (self , function_path : str ):
573
+ indexed_functions = loader .index_function_app (function_path )
574
+ logger .info ('Indexed function app and found %s functions' ,
575
+ len (indexed_functions ))
576
+
577
+ if indexed_functions :
578
+ indexed_function_logs : List [str ] = []
579
+ for func in indexed_functions :
580
+ function_log = "Function Name: {}, Function Binding: {}" \
581
+ .format (func .get_function_name (),
582
+ [(binding .type , binding .name ) for binding in
583
+ func .get_bindings ()])
584
+ indexed_function_logs .append (function_log )
585
+
586
+ logger .info (
587
+ 'Successfully processed FunctionMetadataRequest for '
588
+ 'functions: %s' , " " .join (indexed_function_logs ))
589
+
590
+ fx_metadata_results = loader .process_indexed_function (
591
+ self ._functions ,
592
+ indexed_functions )
593
+
594
+ return fx_metadata_results
595
+
580
596
async def _handle__close_shared_memory_resources_request (self , request ):
581
597
"""
582
598
Frees any memory maps that were produced as output for a given
0 commit comments