Ejemplo n.º 1
0
        public LanguageWorkerChannelManager(IScriptEventManager eventManager, IEnvironment environment, IRpcServer rpcServer, ILoggerFactory loggerFactory, IOptions <LanguageWorkerOptions> languageWorkerOptions,
                                            IOptionsMonitor <ScriptApplicationHostOptions> applicationHostOptions, ILanguageWorkerConsoleLogSource consoleLogSource)
        {
            _rpcServer              = rpcServer;
            _environment            = environment ?? throw new ArgumentNullException(nameof(environment));
            _eventManager           = eventManager;
            _loggerFactory          = loggerFactory;
            _logger                 = loggerFactory.CreateLogger(ScriptConstants.LogCategoryLanguageWorkerChannelManager);
            _workerConfigs          = languageWorkerOptions.Value.WorkerConfigs;
            _applicationHostOptions = applicationHostOptions;
            _consoleLogSource       = consoleLogSource;

            _processFactory = new DefaultWorkerProcessFactory();
            try
            {
                _processRegistry = ProcessRegistryFactory.Create();
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Unable to create process registry");
            }

            _shutdownStandbyWorkerChannels = ScheduleShutdownStandbyChannels;
            _shutdownStandbyWorkerChannels = _shutdownStandbyWorkerChannels.Debounce(5000);
            _rpcChannelReadySubscriptions  = _eventManager.OfType <RpcWebHostChannelReadyEvent>()
                                             .Subscribe(AddOrUpdateWorkerChannels);
        }
        internal LanguageWorkerProcess(string runtime,
                                       string workerId,
                                       string rootScriptPath,
                                       Uri serverUri,
                                       WorkerProcessArguments workerProcessArguments,
                                       IScriptEventManager eventManager,
                                       IWorkerProcessFactory processFactory,
                                       IProcessRegistry processRegistry,
                                       ILogger workerProcessLogger,
                                       ILanguageWorkerConsoleLogSource consoleLogSource)
        {
            _runtime             = runtime;
            _workerId            = workerId;
            _processFactory      = processFactory;
            _processRegistry     = processRegistry;
            _workerProcessLogger = workerProcessLogger;
            _consoleLogSource    = consoleLogSource;
            _eventManager        = eventManager;

            var workerContext = new WorkerContext()
            {
                RequestId        = Guid.NewGuid().ToString(),
                MaxMessageLength = LanguageWorkerConstants.DefaultMaxMessageLengthBytes,
                WorkerId         = _workerId,
                Arguments        = workerProcessArguments,
                WorkingDirectory = rootScriptPath,
                ServerUri        = serverUri,
            };

            _process = _processFactory.CreateWorkerProcess(workerContext);
        }
 internal WorkerProcess(IScriptEventManager eventManager, IProcessRegistry processRegistry, ILogger workerProcessLogger, ILanguageWorkerConsoleLogSource consoleLogSource)
 {
     _processRegistry     = processRegistry;
     _workerProcessLogger = workerProcessLogger;
     _consoleLogSource    = consoleLogSource;
     _eventManager        = eventManager;
 }
Ejemplo n.º 4
0
        public LanguageWorkerConsoleLogService(ILoggerFactory loggerFactory, ILanguageWorkerConsoleLogSource consoleLogSource)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _source = consoleLogSource ?? throw new ArgumentNullException(nameof(consoleLogSource));
            _logger = loggerFactory.CreateLogger(LanguageWorkerConstants.FunctionConsoleLogCategoryName);
        }
Ejemplo n.º 5
0
 public HttpWorkerProcessFactory(IScriptEventManager eventManager,
                                 ILoggerFactory loggerFactory,
                                 IWorkerProcessFactory defaultWorkerProcessFactory,
                                 IProcessRegistry processRegistry,
                                 ILanguageWorkerConsoleLogSource consoleLogSource)
 {
     _loggerFactory        = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _eventManager         = eventManager ?? throw new ArgumentNullException(nameof(eventManager));
     _consoleLogSource     = consoleLogSource ?? throw new ArgumentNullException(nameof(consoleLogSource));
     _workerProcessFactory = defaultWorkerProcessFactory ?? throw new ArgumentNullException(nameof(defaultWorkerProcessFactory));
     _processRegistry      = processRegistry ?? throw new ArgumentNullException(nameof(processRegistry));
 }
Ejemplo n.º 6
0
        internal LanguageWorkerChannel(
            string workerId,
            string rootScriptPath,
            IScriptEventManager eventManager,
            IWorkerProcessFactory processFactory,
            IProcessRegistry processRegistry,
            WorkerConfig workerConfig,
            Uri serverUri,
            ILoggerFactory loggerFactory,
            IMetricsLogger metricsLogger,
            int attemptCount,
            ILanguageWorkerConsoleLogSource consoleLogSource,
            bool isWebHostChannel = false,
            IOptions <ManagedDependencyOptions> managedDependencyOptions = null)
        {
            _workerId            = workerId;
            _rootScriptPath      = rootScriptPath;
            _eventManager        = eventManager;
            _processFactory      = processFactory;
            _processRegistry     = processRegistry;
            _workerConfig        = workerConfig;
            _serverUri           = serverUri;
            _workerChannelLogger = loggerFactory.CreateLogger($"Worker.{workerConfig.Language}.{_workerId}");
            _consoleLogSource    = consoleLogSource;
            _isWebHostChannel    = isWebHostChannel;

            _inboundWorkerEvents = _eventManager.OfType <InboundEvent>()
                                   .Where(msg => msg.WorkerId == _workerId);

            _eventSubscriptions.Add(_inboundWorkerEvents
                                    .Where(msg => msg.MessageType == MsgType.RpcLog)
                                    .Subscribe(Log));

            _eventSubscriptions.Add(_eventManager.OfType <FileEvent>()
                                    .Where(msg => Config.Extensions.Contains(Path.GetExtension(msg.FileChangeArguments.FullPath)))
                                    .Throttle(TimeSpan.FromMilliseconds(300)) // debounce
                                    .Subscribe(msg => _eventManager.Publish(new HostRestartEvent())));

            _eventSubscriptions.Add(_inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.FunctionLoadResponse)
                                    .Subscribe((msg) => LoadResponse(msg.Message.FunctionLoadResponse)));

            _eventSubscriptions.Add(_inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.InvocationResponse)
                                    .Subscribe((msg) => InvokeResponse(msg.Message.InvocationResponse)));

            _startLatencyMetric       = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, workerConfig.Language, attemptCount));
            _managedDependencyOptions = managedDependencyOptions;

            _state = LanguageWorkerChannelState.Default;
        }
 public LanguageWorkerProcessFactory(IRpcServer rpcServer,
                                     IOptions <LanguageWorkerOptions> languageWorkerOptions,
                                     IScriptEventManager eventManager,
                                     ILoggerFactory loggerFactory,
                                     IWorkerProcessFactory defaultWorkerProcessFactory,
                                     IProcessRegistry processRegistry,
                                     ILanguageWorkerConsoleLogSource consoleLogSource)
 {
     _loggerFactory        = loggerFactory;
     _eventManager         = eventManager;
     _rpcServer            = rpcServer;
     _workerConfigs        = languageWorkerOptions.Value.WorkerConfigs;
     _consoleLogSource     = consoleLogSource;
     _workerProcessFactory = defaultWorkerProcessFactory;
     _processRegistry      = processRegistry;
 }
 internal HttpWorkerProcess(string workerId,
                            string rootScriptPath,
                            WorkerProcessArguments workerProcessArguments,
                            IScriptEventManager eventManager,
                            IWorkerProcessFactory processFactory,
                            IProcessRegistry processRegistry,
                            ILogger workerProcessLogger,
                            ILanguageWorkerConsoleLogSource consoleLogSource)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource)
 {
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _scriptRootPath         = rootScriptPath;
     _workerProcessArguments = workerProcessArguments;
 }
Ejemplo n.º 9
0
 internal RpcWorkerProcess(string runtime,
                           string workerId,
                           string rootScriptPath,
                           Uri serverUri,
                           WorkerProcessArguments workerProcessArguments,
                           IScriptEventManager eventManager,
                           IWorkerProcessFactory processFactory,
                           IProcessRegistry processRegistry,
                           ILogger workerProcessLogger,
                           ILanguageWorkerConsoleLogSource consoleLogSource)
     : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource)
 {
     _runtime                = runtime;
     _processFactory         = processFactory;
     _eventManager           = eventManager;
     _workerProcessLogger    = workerProcessLogger;
     _workerId               = workerId;
     _serverUri              = serverUri;
     _scriptRootPath         = rootScriptPath;
     _workerProcessArguments = workerProcessArguments;
 }