internal HttpWorkerChannel( string workerId, ILanguageWorkerProcess languageWorkerProcess, IHttpInvokerService httpInvokerService, ILogger logger, IMetricsLogger metricsLogger, int attemptCount) { Id = workerId; _languageWorkerProcess = languageWorkerProcess; _workerChannelLogger = logger; _httpInvokerService = httpInvokerService; _startLatencyMetric = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, "HttpInvoker", attemptCount)); }
public IHttpWorkerChannel Create(string scriptRootPath, IMetricsLogger metricsLogger, int attemptCount) { string workerId = Guid.NewGuid().ToString(); ILogger workerLogger = _loggerFactory.CreateLogger($"Worker.HttpInvokerChannel.{workerId}"); ILanguageWorkerProcess httpWorkerProcess = _httpInvokerProcessFactory.Create(workerId, scriptRootPath, _httpInvokerOptions.Arguments); return(new HttpWorkerChannel( workerId, httpWorkerProcess, _httpInvokerService, workerLogger, metricsLogger, attemptCount)); }
internal LanguageWorkerChannel( string workerId, string rootScriptPath, IScriptEventManager eventManager, WorkerConfig workerConfig, ILanguageWorkerProcess languageWorkerProcess, ILogger logger, IMetricsLogger metricsLogger, int attemptCount, IOptions <ManagedDependencyOptions> managedDependencyOptions = null) { _workerId = workerId; _rootScriptPath = rootScriptPath; _eventManager = eventManager; _workerConfig = workerConfig; _runtime = workerConfig.Language; _languageWorkerProcess = languageWorkerProcess; _workerChannelLogger = logger; _workerCapabilities = new Capabilities(_workerChannelLogger); _inboundWorkerEvents = _eventManager.OfType <InboundEvent>() .Where(msg => msg.WorkerId == _workerId); _eventSubscriptions.Add(_inboundWorkerEvents .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && !msg.IsLogOfCategory(RpcLogCategory.System)) .Subscribe(Log)); _eventSubscriptions.Add(_inboundWorkerEvents .Where(msg => msg.IsMessageOfType(MsgType.RpcLog) && msg.IsLogOfCategory(RpcLogCategory.System)) .Subscribe(SystemLog)); _eventSubscriptions.Add(_eventManager.OfType <FileEvent>() .Where(msg => _workerConfig.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 ILanguageWorkerChannel Create(string scriptRootPath, string runtime, IMetricsLogger metricsLogger, int attemptCount, IOptions <ManagedDependencyOptions> managedDependencyOptions = null) { var languageWorkerConfig = _workerConfigs.Where(c => c.Description.Language.Equals(runtime, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (languageWorkerConfig == null) { throw new InvalidOperationException($"WorkerCofig for runtime: {runtime} not found"); } string workerId = Guid.NewGuid().ToString(); ILogger workerLogger = _loggerFactory.CreateLogger($"Worker.LanguageWorkerChannel.{runtime}.{workerId}"); ILanguageWorkerProcess languageWorkerProcess = _rpcWorkerProcessFactory.Create(workerId, runtime, scriptRootPath); return(new LanguageWorkerChannel( workerId, scriptRootPath, _eventManager, languageWorkerConfig, languageWorkerProcess, workerLogger, metricsLogger, attemptCount, managedDependencyOptions)); }