public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions)
        {
            if (_environment.IsPlaceholderModeEnabled())
            {
                return;
            }
            _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions);
            if (string.IsNullOrEmpty(_workerRuntime) || _workerRuntime.Equals(LanguageWorkerConstants.DotNetLanguageWorkerName, StringComparison.InvariantCultureIgnoreCase))
            {
                // Shutdown any placeholder channels for empty function apps or dotnet function apps.
                // This is needed as specilization does not kill standby placeholder channels if worker runtime is not set.
                // Debouce to ensure this does not effect cold start
                _shutdownStandbyWorkerChannels();
                return;
            }

            if (Utility.IsSupportedRuntime(_workerRuntime, _workerConfigs))
            {
                foreach (var functionMetadata in functions)
                {
                    _workerState.Functions.OnNext(functionMetadata);
                }
                State = FunctionDispatcherState.Initializing;
                IEnumerable <ILanguageWorkerChannel> initializedChannels = _languageWorkerChannelManager.GetChannels(_workerRuntime);
                if (initializedChannels != null)
                {
                    foreach (var initializedChannel in initializedChannels)
                    {
                        _logger.LogDebug("Found initialized language worker channel for runtime: {workerRuntime} workerId:{workerId}", _workerRuntime, initializedChannel.Id);
                        initializedChannel.RegisterFunctions(_workerState.Functions);
                    }
                    StartWorkerProcesses(initializedChannels.Count(), InitializeWebhostLanguageWorkerChannel);
                    State = FunctionDispatcherState.Initialized;
                }
                else
                {
                    await InitializeJobhostLanguageWorkerChannelAsync(0);

                    StartWorkerProcesses(1, InitializeJobhostLanguageWorkerChannelAsync);
                }
            }
        }
Example #2
0
        private async Task <int> WaitForWebhostWorkerChannelsToStartup(ILanguageWorkerChannelManager channelManager, int expectedCount, string language)
        {
            int currentChannelCount = 0;
            await TestHelpers.Await(() =>
            {
                currentChannelCount = channelManager.GetChannels(language).Count();
                return(currentChannelCount == expectedCount);
            }, pollingInterval : 4 * 1000, timeout : 60 * 1000);

            return(currentChannelCount);
        }