internal void AddProvider(string workerDir) { try { string workerConfigPath = Path.Combine(workerDir, LanguageWorkerConstants.WorkerConfigFileName); if (!File.Exists(workerConfigPath)) { _logger.LogDebug($"Did not find worker config file at: {workerConfigPath}"); return; } _logger.LogDebug($"Found worker config: {workerConfigPath}"); string json = File.ReadAllText(workerConfigPath); JObject workerConfig = JObject.Parse(json); RpcWorkerDescription workerDescription = workerConfig.Property(OutOfProcConstants.WorkerDescription).Value.ToObject <RpcWorkerDescription>(); workerDescription.WorkerDirectory = workerDir; var languageSection = _config.GetSection($"{LanguageWorkerConstants.LanguageWorkersSectionName}:{workerDescription.Language}"); workerDescription.Arguments = workerDescription.Arguments ?? new List <string>(); GetDefaultExecutablePathFromAppSettings(workerDescription, languageSection); AddArgumentsFromAppSettings(workerDescription, languageSection); workerDescription.ApplyDefaultsAndValidate(); _workerDescripionDictionary[workerDescription.Language] = workerDescription; if (IsHydrationNeeded(workerDescription.DefaultWorkerPath)) { workerDescription.DefaultWorkerPath = GetHydratedWorkerPath(workerDescription); } } catch (Exception ex) { _logger?.LogError(ex, $"Failed to initialize worker provider for: {workerDir}"); } }
private static WorkerDescription GetWorkerDescriptionFromProfiles(string key, Dictionary <string, RpcWorkerDescription> descriptionProfiles, RpcWorkerDescription defaultWorkerDescription) { RpcWorkerDescription profileDescription = null; if (descriptionProfiles.TryGetValue(key, out profileDescription)) { profileDescription.Arguments = profileDescription.Arguments?.Count > 0 ? profileDescription.Arguments : defaultWorkerDescription.Arguments; profileDescription.DefaultExecutablePath = string.IsNullOrEmpty(profileDescription.DefaultExecutablePath) ? defaultWorkerDescription.DefaultExecutablePath : profileDescription.DefaultExecutablePath; profileDescription.DefaultWorkerPath = string.IsNullOrEmpty(profileDescription.DefaultWorkerPath) ? defaultWorkerDescription.DefaultWorkerPath : profileDescription.DefaultWorkerPath; profileDescription.Extensions = profileDescription.Extensions ?? defaultWorkerDescription.Extensions; profileDescription.Language = string.IsNullOrEmpty(profileDescription.Language) ? defaultWorkerDescription.Language : profileDescription.Language; profileDescription.WorkerDirectory = string.IsNullOrEmpty(profileDescription.WorkerDirectory) ? defaultWorkerDescription.WorkerDirectory : profileDescription.WorkerDirectory; return(profileDescription); } return(defaultWorkerDescription); }
internal static void AddArgumentsFromAppSettings(RpcWorkerDescription workerDescription, IConfigurationSection languageSection) { if (workerDescription.Language.Equals(LanguageWorkerConstants.JavaLanguageWorkerName)) { // For Java either provide arguments via JAVA_OPTS or languageWorkers:java:arguments. Both cannot be supported string javaOpts = ScriptSettingsManager.Instance.GetSetting("JAVA_OPTS"); if (!string.IsNullOrEmpty(javaOpts)) { workerDescription.Arguments.Add(javaOpts); return; } } var argumentsSection = languageSection.GetSection($"{OutOfProcConstants.WorkerDescriptionArguments}"); if (argumentsSection.Value != null) { workerDescription.Arguments.AddRange(Regex.Split(argumentsSection.Value, @"\s+")); } }
internal string GetHydratedWorkerPath(RpcWorkerDescription description) { if (string.IsNullOrEmpty(description.DefaultWorkerPath)) { return(null); } OSPlatform os = _systemRuntimeInformation.GetOSPlatform(); Architecture architecture = _systemRuntimeInformation.GetOSArchitecture(); string version = _environment.GetEnvironmentVariable(LanguageWorkerConstants.FunctionWorkerRuntimeVersionSettingName); if (string.IsNullOrEmpty(version)) { version = description.DefaultRuntimeVersion; } description.ValidateWorkerPath(description.DefaultWorkerPath, os, architecture, version); return(description.DefaultWorkerPath.Replace(LanguageWorkerConstants.OSPlaceholder, os.ToString()) .Replace(LanguageWorkerConstants.ArchitecturePlaceholder, architecture.ToString()) .Replace(LanguageWorkerConstants.RuntimeVersionPlaceholder, version)); }