public RpcFunctionInvocationDispatcher(IOptions <ScriptJobHostOptions> scriptHostOptions,
                                               IMetricsLogger metricsLogger,
                                               IEnvironment environment,
                                               IApplicationLifetime applicationLifetime,
                                               IScriptEventManager eventManager,
                                               ILoggerFactory loggerFactory,
                                               IRpcWorkerChannelFactory rpcWorkerChannelFactory,
                                               IOptions <LanguageWorkerOptions> languageWorkerOptions,
                                               IWebHostRpcWorkerChannelManager webHostLanguageWorkerChannelManager,
                                               IJobHostRpcWorkerChannelManager jobHostLanguageWorkerChannelManager,
                                               IOptions <ManagedDependencyOptions> managedDependencyOptions,
                                               IRpcFunctionInvocationDispatcherLoadBalancer functionDispatcherLoadBalancer)
        {
            _metricsLogger       = metricsLogger;
            _scriptOptions       = scriptHostOptions.Value;
            _environment         = environment;
            _applicationLifetime = applicationLifetime;
            _webHostLanguageWorkerChannelManager = webHostLanguageWorkerChannelManager;
            _jobHostLanguageWorkerChannelManager = jobHostLanguageWorkerChannelManager;
            _eventManager             = eventManager;
            _workerConfigs            = languageWorkerOptions.Value.WorkerConfigs;
            _managedDependencyOptions = managedDependencyOptions ?? throw new ArgumentNullException(nameof(managedDependencyOptions));
            _logger = loggerFactory.CreateLogger <RpcFunctionInvocationDispatcher>();
            _rpcWorkerChannelFactory = rpcWorkerChannelFactory;
            _workerRuntime           = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);

            var processCount = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionsWorkerProcessCountSettingName);

            _maxProcessCount = (processCount != null && int.Parse(processCount) > 1) ? int.Parse(processCount) : 1;
            _maxProcessCount = _maxProcessCount > _maxAllowedProcessCount ? _maxAllowedProcessCount : _maxProcessCount;
            _functionDispatcherLoadBalancer = functionDispatcherLoadBalancer;

            State = FunctionInvocationDispatcherState.Default;
            ErrorEventsThreshold = 3 * _maxProcessCount;

            _workerErrorSubscription = _eventManager.OfType <WorkerErrorEvent>()
                                       .Subscribe(WorkerError);
            _workerRestartSubscription = _eventManager.OfType <WorkerRestartEvent>()
                                         .Subscribe(WorkerRestart);

            _shutdownStandbyWorkerChannels = ShutdownWebhostLanguageWorkerChannels;
            _shutdownStandbyWorkerChannels = _shutdownStandbyWorkerChannels.Debounce(milliseconds: 5000);
        }
Ejemplo n.º 2
0
        public FunctionInvocationDispatcherFactory(IOptions <ScriptJobHostOptions> scriptHostOptions,
                                                   IMetricsLogger metricsLogger,
                                                   IApplicationLifetime applicationLifetime,
                                                   IScriptEventManager eventManager,
                                                   ILoggerFactory loggerFactory,
                                                   IHttpWorkerChannelFactory httpWorkerChannelFactory,
                                                   IRpcWorkerChannelFactory rpcWorkerChannelFactory,
                                                   IOptions <HttpWorkerOptions> httpWorkerOptions,
                                                   IOptionsMonitor <LanguageWorkerOptions> rpcWorkerOptions,
                                                   IEnvironment environment,
                                                   IWebHostRpcWorkerChannelManager webHostLanguageWorkerChannelManager,
                                                   IJobHostRpcWorkerChannelManager jobHostLanguageWorkerChannelManager,
                                                   IOptions <ManagedDependencyOptions> managedDependencyOptions,
                                                   IRpcFunctionInvocationDispatcherLoadBalancer functionDispatcherLoadBalancer,
                                                   IOptions <WorkerConcurrencyOptions> workerConcurrencyOptions)
        {
            if (httpWorkerOptions.Value == null)
            {
                throw new ArgumentNullException(nameof(httpWorkerOptions.Value));
            }

            if (httpWorkerOptions.Value.Description != null)
            {
                _functionDispatcher = new HttpFunctionInvocationDispatcher(scriptHostOptions, metricsLogger, applicationLifetime, eventManager, loggerFactory, httpWorkerChannelFactory);
                return;
            }
            _functionDispatcher = new RpcFunctionInvocationDispatcher(scriptHostOptions,
                                                                      metricsLogger,
                                                                      environment,
                                                                      applicationLifetime,
                                                                      eventManager,
                                                                      loggerFactory,
                                                                      rpcWorkerChannelFactory,
                                                                      rpcWorkerOptions,
                                                                      webHostLanguageWorkerChannelManager,
                                                                      jobHostLanguageWorkerChannelManager,
                                                                      managedDependencyOptions,
                                                                      functionDispatcherLoadBalancer,
                                                                      workerConcurrencyOptions);
        }
        public RpcFunctionInvocationDispatcher(IOptions <ScriptJobHostOptions> scriptHostOptions,
                                               IMetricsLogger metricsLogger,
                                               IEnvironment environment,
                                               IApplicationLifetime applicationLifetime,
                                               IScriptEventManager eventManager,
                                               ILoggerFactory loggerFactory,
                                               IRpcWorkerChannelFactory rpcWorkerChannelFactory,
                                               IOptionsMonitor <LanguageWorkerOptions> languageWorkerOptions,
                                               IWebHostRpcWorkerChannelManager webHostLanguageWorkerChannelManager,
                                               IJobHostRpcWorkerChannelManager jobHostLanguageWorkerChannelManager,
                                               IOptions <ManagedDependencyOptions> managedDependencyOptions,
                                               IRpcFunctionInvocationDispatcherLoadBalancer functionDispatcherLoadBalancer,
                                               IOptions <WorkerConcurrencyOptions> workerConcurrencyOptions)
        {
            _metricsLogger       = metricsLogger;
            _scriptOptions       = scriptHostOptions.Value;
            _environment         = environment ?? throw new ArgumentNullException(nameof(environment));
            _applicationLifetime = applicationLifetime;
            _webHostLanguageWorkerChannelManager = webHostLanguageWorkerChannelManager;
            _jobHostLanguageWorkerChannelManager = jobHostLanguageWorkerChannelManager;
            _eventManager             = eventManager;
            _workerConfigs            = languageWorkerOptions?.CurrentValue?.WorkerConfigs ?? throw new ArgumentNullException(nameof(languageWorkerOptions));
            _managedDependencyOptions = managedDependencyOptions ?? throw new ArgumentNullException(nameof(managedDependencyOptions));
            _logger = loggerFactory.CreateLogger <RpcFunctionInvocationDispatcher>();
            _rpcWorkerChannelFactory        = rpcWorkerChannelFactory;
            _workerRuntime                  = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
            _functionDispatcherLoadBalancer = functionDispatcherLoadBalancer;
            _workerConcurrencyOptions       = workerConcurrencyOptions;
            _workerIndexing                 = Utility.CanWorkerIndex(_workerConfigs, _environment);
            State = FunctionInvocationDispatcherState.Default;

            _workerErrorSubscription   = _eventManager.OfType <WorkerErrorEvent>().Subscribe(WorkerError);
            _workerRestartSubscription = _eventManager.OfType <WorkerRestartEvent>().Subscribe(WorkerRestart);

            _shutdownStandbyWorkerChannels = ShutdownWebhostLanguageWorkerChannels;
            _shutdownStandbyWorkerChannels = _shutdownStandbyWorkerChannels.Debounce(milliseconds: 5000);

            _maxProcessCount = new Lazy <Task <int> >(GetMaxProcessCount);
        }