public LanguageWorkerChannel( ScriptJobHostOptions scriptConfig, IScriptEventManager eventManager, IWorkerProcessFactory processFactory, IProcessRegistry processRegistry, IObservable <FunctionRegistrationContext> functionRegistrations, WorkerConfig workerConfig, Uri serverUri, ILoggerFactory loggerFactory, IMetricsLogger metricsLogger, int attemptCount) { _workerId = Guid.NewGuid().ToString(); _scriptConfig = scriptConfig; _eventManager = eventManager; _processFactory = processFactory; _processRegistry = processRegistry; _functionRegistrations = functionRegistrations; _workerConfig = workerConfig; _serverUri = serverUri; _workerChannelLogger = loggerFactory.CreateLogger($"Worker.{workerConfig.Language}.{_workerId}"); _userLogsConsoleLogger = loggerFactory.CreateLogger(LanguageWorkerConstants.FunctionConsoleLogCategoryName); _inboundWorkerEvents = _eventManager.OfType <InboundEvent>() .Where(msg => msg.WorkerId == _workerId); _eventSubscriptions.Add(_inboundWorkerEvents .Where(msg => msg.MessageType == MsgType.RpcLog) .Subscribe(Log)); _eventSubscriptions.Add(_eventManager.OfType <RpcEvent>() .Where(msg => msg.WorkerId == _workerId) .Subscribe(msg => { var jsonMsg = JsonConvert.SerializeObject(msg, _verboseSerializerSettings); _userLogsConsoleLogger.LogTrace(jsonMsg); })); _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()))); _startLatencyMetric = metricsLogger.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, workerConfig.Language, attemptCount)); StartWorker(); }
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 LanguageWorkerChannel( ScriptHostConfiguration scriptConfig, IScriptEventManager eventManager, IWorkerProcessFactory processFactory, IProcessRegistry processRegistry, IObservable <FunctionRegistrationContext> functionRegistrations, WorkerConfig workerConfig, Uri serverUri, ILoggerFactory loggerFactory) { _workerId = Guid.NewGuid().ToString(); _scriptConfig = scriptConfig; _eventManager = eventManager; _processFactory = processFactory; _processRegistry = processRegistry; _functionRegistrations = functionRegistrations; _workerConfig = workerConfig; _serverUri = serverUri; _logger = loggerFactory.CreateLogger($"Worker.{workerConfig.Language}.{_workerId}"); _inboundWorkerEvents = _eventManager.OfType <InboundEvent>() .Where(msg => msg.WorkerId == _workerId); _eventSubscriptions.Add(_inboundWorkerEvents .Where(msg => msg.MessageType == MsgType.RpcLog) .Subscribe(Log)); if (scriptConfig.LogFilter.Filter("Worker", LogLevel.Trace)) { _eventSubscriptions.Add(_eventManager.OfType <RpcEvent>() .Where(msg => msg.WorkerId == _workerId) .Subscribe(msg => { var jsonMsg = JsonConvert.SerializeObject(msg, _verboseSerializerSettings); // TODO: change to trace when ILogger & TraceWriter merge (issues with file trace writer) _logger.LogInformation(jsonMsg); })); } _eventSubscriptions.Add(_eventManager.OfType <FileEvent>() .Where(msg => Path.GetExtension(msg.FileChangeArguments.FullPath) == Config.Extension) .Throttle(TimeSpan.FromMilliseconds(300)) // debounce .Subscribe(msg => _eventManager.Publish(new HostRestartEvent()))); StartWorker(); }
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 LanguageWorkerState CreateWorkerState(string language) { ILanguageWorkerChannel initializedChannel = _languageWorkerChannelManager.GetChannel(language); if (initializedChannel != null) { return(CreateWorkerStateWithExistingChannel(language, initializedChannel)); } else { var state = new LanguageWorkerState(); WorkerConfig config = _workerConfigs.Where(c => c.Language.Equals(language, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); state.Channel = ChannelFactory(language, state.Functions, 0); _workerStates[language] = state; return(state); } }
public IList <WorkerConfig> GetConfigs() { BuildWorkerProviderDictionary(); var result = new List <WorkerConfig>(); foreach (var provider in WorkerProviders) { var description = provider.GetDescription(); _logger.LogDebug($"Worker path for language worker {description.Language}: {description.WorkerDirectory}"); var arguments = new WorkerProcessArguments() { ExecutablePath = description.DefaultExecutablePath, WorkerPath = description.GetWorkerPath() }; if (description.Language.Equals(LanguageWorkerConstants.JavaLanguageWorkerName)) { arguments.ExecutablePath = GetExecutablePathForJava(description.DefaultExecutablePath); } if (provider.TryConfigureArguments(arguments, _logger)) { var config = new WorkerConfig() { Description = description, Arguments = arguments }; result.Add(config); } else { _logger.LogError($"Could not configure language worker {description.Language}."); } } return(result); }