internal void ProcessFunctionMetadataResponses()

in src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs [973:1060]


        internal void ProcessFunctionMetadataResponses(FunctionMetadataResponse functionMetadataResponse)
        {
            _workerChannelLogger.LogDebug("Received the worker function metadata response from worker {worker_id}", _workerId);

            if (functionMetadataResponse.Result.IsFailure(out Exception metadataResponseEx))
            {
                _workerChannelLogger?.LogError(metadataResponseEx, "Worker failed to index functions");
            }

            var functions = new List<RawFunctionMetadata>();

            if (functionMetadataResponse.UseDefaultMetadataIndexing == false)
            {
                foreach (var metadata in functionMetadataResponse.FunctionMetadataResults)
                {
                    if (metadata == null)
                    {
                        continue;
                    }
                    if (metadata.Status != null && metadata.Status.IsFailure(out Exception metadataRequestEx))
                    {
                        _workerChannelLogger.LogError("Worker failed to index function {functionId}", metadata.FunctionId);
                        _metadataRequestErrors[metadata.FunctionId] = metadataRequestEx;
                    }

                    var functionMetadata = new FunctionMetadata()
                    {
                        FunctionDirectory = metadata.Directory,
                        ScriptFile = metadata.ScriptFile,
                        EntryPoint = metadata.EntryPoint,
                        Name = metadata.Name,
                        Language = metadata.Language
                    };

                    if (metadata.RetryOptions is not null)
                    {
                        functionMetadata.Retry = new RetryOptions
                        {
                            MaxRetryCount = metadata.RetryOptions.MaxRetryCount,
                            Strategy = metadata.RetryOptions.RetryStrategy.ToRetryStrategy()
                        };

                        if (functionMetadata.Retry.Strategy is RetryStrategy.FixedDelay)
                        {
                            functionMetadata.Retry.DelayInterval = metadata.RetryOptions.DelayInterval?.ToTimeSpan();
                        }
                        else
                        {
                            functionMetadata.Retry.MinimumInterval = metadata.RetryOptions.MinimumInterval?.ToTimeSpan();
                            functionMetadata.Retry.MaximumInterval = metadata.RetryOptions.MaximumInterval?.ToTimeSpan();
                        }
                    }

                    functionMetadata.SetFunctionId(metadata.FunctionId);

                    foreach (var property in metadata.Properties)
                    {
                        if (!functionMetadata.Properties.TryAdd(property.Key, property.Value?.ToString()))
                        {
                            _workerChannelLogger?.LogDebug("{metadataPropertyKey} is already a part of metadata properties for {functionId}", property.Key, metadata.FunctionId);
                        }
                    }

                    var bindings = new List<string>();
                    foreach (string binding in metadata.RawBindings)
                    {
                        bindings.Add(binding);
                    }

                    functions.Add(new RawFunctionMetadata()
                    {
                        Metadata = functionMetadata,
                        Bindings = bindings,
                        UseDefaultMetadataIndexing = functionMetadataResponse.UseDefaultMetadataIndexing
                    });
                }
            }
            else
            {
                functions.Add(new RawFunctionMetadata()
                {
                    UseDefaultMetadataIndexing = functionMetadataResponse.UseDefaultMetadataIndexing
                });
            }

            // set it as task result because we cannot directly return from SendWorkerMetadataRequest
            _functionsIndexingTask.SetResult(functions);
        }