private void AddOrUpdateWorkerChannels(RpcJobHostChannelReadyEvent rpcChannelReadyEvent)
 {
     if (!_disposing)
     {
         _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}.", rpcChannelReadyEvent.Language);
         rpcChannelReadyEvent.LanguageWorkerChannel.RegisterFunctions(_workerState.Functions);
         State = FunctionDispatcherState.Initialized;
     }
 }
 private void AddOrUpdateWorkerChannels(RpcJobHostChannelReadyEvent rpcChannelReadyEvent)
 {
     if (!_disposing)
     {
         _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}. workerId:{id}", rpcChannelReadyEvent.Language, rpcChannelReadyEvent.LanguageWorkerChannel.Id);
         rpcChannelReadyEvent.LanguageWorkerChannel.SendFunctionLoadRequests();
         State = FunctionDispatcherState.Initialized;
     }
 }
        public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions)
        {
            if (functions == null || !functions.Any())
            {
                // do not initialize function dispachter if there are no functions
                return;
            }

            State = FunctionDispatcherState.Initializing;
            await InitializeJobhostLanguageWorkerChannelAsync(0);
        }
Exemplo n.º 4
0
        public async Task InitializeAsync(IEnumerable <FunctionMetadata> functions)
        {
            if (_environment.IsPlaceholderModeEnabled())
            {
                return;
            }

            _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions);
            _functions     = 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 (functions == null || functions.Count() == 0)
            {
                // do not initialize function dispachter if there are no functions
                return;
            }

            if (Utility.IsSupportedRuntime(_workerRuntime, _workerConfigs))
            {
                State = FunctionDispatcherState.Initializing;
                Dictionary <string, TaskCompletionSource <ILanguageWorkerChannel> > webhostLanguageWorkerChannels = _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime);
                if (webhostLanguageWorkerChannels != null)
                {
                    foreach (string workerId in webhostLanguageWorkerChannels.Keys)
                    {
                        if (webhostLanguageWorkerChannels.TryGetValue(workerId, out TaskCompletionSource <ILanguageWorkerChannel> initializedLanguageWorkerChannelTask))
                        {
                            _logger.LogDebug("Found initialized language worker channel for runtime: {workerRuntime} workerId:{workerId}", _workerRuntime, workerId);
                            ILanguageWorkerChannel initializedLanguageWorkerChannel = await initializedLanguageWorkerChannelTask.Task;
                            initializedLanguageWorkerChannel.SetupFunctionInvocationBuffers(_functions);
                            initializedLanguageWorkerChannel.SendFunctionLoadRequests();
                        }
                    }
                    StartWorkerProcesses(webhostLanguageWorkerChannels.Count(), InitializeWebhostLanguageWorkerChannel);
                    State = FunctionDispatcherState.Initialized;
                }
                else
                {
                    await InitializeJobhostLanguageWorkerChannelAsync(0);

                    StartWorkerProcesses(1, InitializeJobhostLanguageWorkerChannelAsync);
                }
            }
        }
 internal Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount)
 {
     // TODO: Add process managment for http invoker
     _httpInvokerChannel = _httpInvokerChannelFactory.Create(_scriptOptions.RootScriptPath, _metricsLogger, attemptCount);
     _httpInvokerChannel.StartWorkerProcessAsync().ContinueWith(workerInitTask =>
     {
         if (workerInitTask.IsCompleted)
         {
             _logger.LogDebug("Adding http invoker channel. workerId:{id}", _httpInvokerChannel.Id);
             State = FunctionDispatcherState.Initialized;
         }
         else
         {
             _logger.LogWarning("Failed to start http invoker process. workerId:{id}", _httpInvokerChannel.Id);
         }
     });
     return(Task.CompletedTask);
 }
        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);
                }
            }
        }
Exemplo n.º 7
0
        internal Task InitializeJobhostLanguageWorkerChannelAsync(int attemptCount)
        {
            var languageWorkerChannel = _languageWorkerChannelFactory.CreateLanguageWorkerChannel(_scriptOptions.RootScriptPath, _workerRuntime, _metricsLogger, attemptCount, _managedDependencyOptions);

            languageWorkerChannel.SetupFunctionInvocationBuffers(_functions);
            _jobHostLanguageWorkerChannelManager.AddChannel(languageWorkerChannel);
            languageWorkerChannel.StartWorkerProcessAsync().ContinueWith(workerInitTask =>
            {
                if (workerInitTask.IsCompleted)
                {
                    _logger.LogDebug("Adding jobhost language worker channel for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                    languageWorkerChannel.SendFunctionLoadRequests();
                    State = FunctionDispatcherState.Initialized;
                }
                else
                {
                    _logger.LogWarning("Failed to start language worker process for runtime: {language}. workerId:{id}", _workerRuntime, languageWorkerChannel.Id);
                }
            });
            return(Task.CompletedTask);
        }