public IList <RpcWorkerConfig> GetConfigs() { using (_metricsLogger.LatencyEvent(MetricEventNames.GetConfigs)) { BuildWorkerProviderDictionary(); var result = new List <RpcWorkerConfig>(); foreach (var description in _workerDescripionDictionary.Values) { _logger.LogDebug($"Worker path for language worker {description.Language}: {description.WorkerDirectory}"); var arguments = new WorkerProcessArguments() { ExecutablePath = description.DefaultExecutablePath, WorkerPath = description.DefaultWorkerPath }; arguments.ExecutableArguments.AddRange(description.Arguments); var config = new RpcWorkerConfig() { Description = description, Arguments = arguments }; result.Add(config); } return(result); } }
public IWorkerProcess Create(string workerId, string runtime, string scriptRootPath) { RpcWorkerConfig workerConfig = _workerConfigs.Where(c => c.Description.Language.Equals(runtime, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); ILogger workerProcessLogger = _loggerFactory.CreateLogger($"Worker.rpcWorkerProcess.{runtime}.{workerId}"); return(new RpcWorkerProcess(runtime, workerId, scriptRootPath, _rpcServer.Uri, workerConfig.Arguments, _eventManager, _workerProcessFactory, _processRegistry, workerProcessLogger, _consoleLogSource)); }
internal void AddProvider(string workerDir) { using (_metricsLogger.LatencyEvent(string.Format(MetricEventNames.AddProvider, workerDir))) { try { string workerConfigPath = Path.Combine(workerDir, RpcWorkerConstants.WorkerConfigFileName); if (!File.Exists(workerConfigPath)) { _logger.LogDebug($"Did not find worker config file at: {workerConfigPath}"); return; } // Parse worker config file _logger.LogDebug($"Found worker config: {workerConfigPath}"); string json = File.ReadAllText(workerConfigPath); JObject workerConfig = JObject.Parse(json); RpcWorkerDescription workerDescription = workerConfig.Property(WorkerConstants.WorkerDescription).Value.ToObject <RpcWorkerDescription>(); workerDescription.WorkerDirectory = workerDir; // Check if any appsettings are provided for that langauge var languageSection = _config.GetSection($"{RpcWorkerConstants.LanguageWorkersSectionName}:{workerDescription.Language}"); workerDescription.Arguments = workerDescription.Arguments ?? new List <string>(); GetWorkerDescriptionFromAppSettings(workerDescription, languageSection); AddArgumentsFromAppSettings(workerDescription, languageSection); // Validate workerDescription workerDescription.ApplyDefaultsAndValidate(Directory.GetCurrentDirectory(), _logger); if (ShouldAddWorkerConfig(workerDescription.Language)) { workerDescription.FormatWorkerPathIfNeeded(_systemRuntimeInformation, _environment, _logger); workerDescription.ThrowIfFileNotExists(workerDescription.DefaultWorkerPath, nameof(workerDescription.DefaultWorkerPath)); workerDescription.ExpandEnvironmentVariables(); WorkerProcessCountOptions workerProcessCount = GetWorkerProcessCount(workerConfig); var arguments = new WorkerProcessArguments() { ExecutablePath = workerDescription.DefaultExecutablePath, WorkerPath = workerDescription.DefaultWorkerPath }; arguments.ExecutableArguments.AddRange(workerDescription.Arguments); var rpcWorkerConfig = new RpcWorkerConfig() { Description = workerDescription, Arguments = arguments, CountOptions = workerProcessCount, }; _workerDescriptionDictionary[workerDescription.Language] = rpcWorkerConfig; ReadLanguageWorkerFile(arguments.WorkerPath); _logger.LogDebug($"Added WorkerConfig for language: {workerDescription.Language}"); } } catch (Exception ex) { _logger?.LogError(ex, $"Failed to initialize worker provider for: {workerDir}"); } } }
internal RpcWorkerChannel( string workerId, IScriptEventManager eventManager, RpcWorkerConfig workerConfig, IWorkerProcess rpcWorkerProcess, ILogger logger, IMetricsLogger metricsLogger, int attemptCount, IEnvironment environment, IOptionsMonitor <ScriptApplicationHostOptions> applicationHostOptions) { _workerId = workerId; _eventManager = eventManager; _workerConfig = workerConfig; _runtime = workerConfig.Description.Language; _rpcWorkerProcess = rpcWorkerProcess; _workerChannelLogger = logger; _metricsLogger = metricsLogger; _environment = environment; _applicationHostOptions = applicationHostOptions; _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.Description.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))); _inboundWorkerEvents.Where(msg => msg.MessageType == MsgType.WorkerStatusResponse) .Subscribe((msg) => ReceiveWorkerStatusResponse(msg.Message.RequestId, msg.Message.WorkerStatusResponse)); _startLatencyMetric = metricsLogger?.LatencyEvent(string.Format(MetricEventNames.WorkerInitializeLatency, workerConfig.Description.Language, attemptCount)); _state = RpcWorkerChannelState.Default; }
internal RpcWorkerProcess(string runtime, string workerId, string rootScriptPath, Uri serverUri, RpcWorkerConfig rpcWorkerConfig, IScriptEventManager eventManager, IWorkerProcessFactory processFactory, IProcessRegistry processRegistry, ILogger workerProcessLogger, IWorkerConsoleLogSource consoleLogSource, IMetricsLogger metricsLogger) : base(eventManager, processRegistry, workerProcessLogger, consoleLogSource, metricsLogger, rpcWorkerConfig.Description.UseStdErrorStreamForErrorsOnly) { _runtime = runtime; _processFactory = processFactory; _eventManager = eventManager; _workerProcessLogger = workerProcessLogger; _workerId = workerId; _serverUri = serverUri; _scriptRootPath = rootScriptPath; _workerProcessArguments = rpcWorkerConfig.Arguments; _workerDirectory = rpcWorkerConfig.Description.WorkerDirectory; }
public IWorkerProcess Create(string workerId, string runtime, string scriptRootPath, RpcWorkerConfig workerConfig) { ILogger workerProcessLogger = _loggerFactory.CreateLogger($"Worker.rpcWorkerProcess.{runtime}.{workerId}"); return(new RpcWorkerProcess(runtime, workerId, scriptRootPath, _rpcServer.Uri, workerConfig, _eventManager, _workerProcessFactory, _processRegistry, workerProcessLogger, _consoleLogSource, _metricsLogger)); }