/// <summary> /// Shows the mode where the user can edit an existing queue /// </summary> private void ShowEditMode() { if (!IsEditMode) { return; } pnlEditDetails.Visible = true; pnlViewDetails.Visible = false; HideSecondaryBlocks(true); cbIsActive.Checked = RockWebFarm.IsEnabled(); tbWebFarmKey.Text = SystemSettings.GetValue(SystemSetting.WEBFARM_KEY); nbPollingMin.IntegerValue = RockWebFarm.GetLowerPollingLimitSeconds(); nbPollingMax.IntegerValue = RockWebFarm.GetUpperPollingLimitSeconds(); nbPollingWait.IntegerValue = RockWebFarm.GetMaxPollingWaitSeconds(); nbPollingDifference.IntegerValue = RockWebFarm.GetMinimumPollingDifferenceSeconds(); }
/// <summary> /// Shows the controls needed /// </summary> public void RenderState() { nbEditModeMessage.Text = string.Empty; var isEnabled = RockWebFarm.IsEnabled(); var hasValidKey = RockWebFarm.HasValidKey(); var isRunning = RockWebFarm.IsRunning(); if (!isEnabled && hasValidKey && isRunning) { hlActive.Text = "Ready (Re-enable)"; hlActive.LabelType = Rock.Web.UI.Controls.LabelType.Warning; } else if (isEnabled && hasValidKey && !isRunning) { hlActive.Text = "Ready (Restart Rock)"; hlActive.LabelType = Rock.Web.UI.Controls.LabelType.Warning; } else if (isEnabled && hasValidKey) { hlActive.Text = "Active"; hlActive.LabelType = Rock.Web.UI.Controls.LabelType.Success; } else { hlActive.Text = "Inactive"; hlActive.LabelType = Rock.Web.UI.Controls.LabelType.Danger; } if (IsEditMode) { ShowEditMode(); } else if (IsViewMode()) { ShowViewMode(); } nbInMemoryBus.Visible = Rock.Bus.RockMessageBus.IsInMemoryTransport; }
/// <summary> /// Save the current record. /// </summary> /// <returns></returns> private void SaveRecord() { RockWebFarm.SetIsEnabled(cbIsActive.Checked); SystemSettings.SetValue(SystemSetting.WEBFARM_KEY, tbWebFarmKey.Text); SystemSettings.SetValue( SystemSetting.WEBFARM_LEADERSHIP_POLLING_INTERVAL_LOWER_LIMIT_SECONDS, (nbPollingMin.IntegerValue ?? RockWebFarm.DefaultValue.DefaultLeadershipPollingIntervalLowerLimitSeconds).ToString()); SystemSettings.SetValue( SystemSetting.WEBFARM_LEADERSHIP_POLLING_INTERVAL_UPPER_LIMIT_SECONDS, (nbPollingMax.IntegerValue ?? RockWebFarm.DefaultValue.DefaultLeadershipPollingIntervalUpperLimitSeconds).ToString()); SystemSettings.SetValue( SystemSetting.WEBFARM_LEADERSHIP_MAX_WAIT_SECONDS, (nbPollingWait.IntegerValue ?? RockWebFarm.DefaultValue.DefaultPollingMaxWaitSeconds).ToString()); SystemSettings.SetValue( SystemSetting.WEBFARM_LEADERSHIP_MIN_POLLING_DIFFERENCE_SECONDS, (nbPollingDifference.IntegerValue ?? RockWebFarm.DefaultValue.DefaultMinimumPollingDifferenceSeconds).ToString()); IsEditMode = false; RenderState(); }
/// <summary> /// Runs various startup operations that need to run prior to RockWeb startup /// </summary> internal static void RunApplicationStartup() { // Indicate to always log to file during initialization. ExceptionLogService.AlwaysLogToFile = true; InitializeRockOrgTimeZone(); StartDateTime = RockDateTime.Now; RockInstanceConfig.SetApplicationStartedDateTime(StartDateTime); // If there are Task.Runs that don't handle their exceptions, this will catch those // so that we can log it. Note that this event won't fire until the Task is disposed. // In most cases, that'll be when GC is collected. So it won't happen immediately. TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; LogStartupMessage("Application Starting"); var runMigrationFileInfo = new FileInfo(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\Run.Migration")); bool hasPendingEFMigrations = runMigrationFileInfo.Exists || HasPendingEFMigrations(); bool ranEFMigrations = MigrateDatabase(hasPendingEFMigrations); ShowDebugTimingMessage("EF Migrations"); ConfigureEntitySaveHooks(); ShowDebugTimingMessage("Configure Entity SaveHooks"); // Now that EF Migrations have gotten the Schema in sync with our Models, // get the RockContext initialized (which can take several seconds) // This will help reduce the chances of multiple instances RockWeb causing problems, // like creating duplicate attributes, or running the same migration in parallel using (var rockContext = new RockContext()) { new AttributeService(rockContext).Get(0); ShowDebugTimingMessage("Initialize RockContext"); } // Configure the values for RockDateTime. RockDateTime.FirstDayOfWeek = Rock.Web.SystemSettings.StartDayOfWeek; InitializeRockGraduationDate(); if (runMigrationFileInfo.Exists) { // fileInfo.Delete() won't do anything if the file doesn't exist (it doesn't throw an exception if it is not there ) // but do the fileInfo.Exists to make this logic more readable runMigrationFileInfo.Delete(); } // Run any plugin migrations bool anyPluginMigrations = MigratePlugins(); ShowDebugTimingMessage("Plugin Migrations"); /* 2020-05-20 MDP * Plugins use Direct SQL to update data, * or other things could have done data updates * So, just in case, clear the cache (which could be Redis) since anything that is in there could be stale */ RockCache.ClearAllCachedItems(false); using (var rockContext = new RockContext()) { LoadCacheObjects(rockContext); ShowDebugTimingMessage("Load Cache Objects"); UpdateAttributesFromRockConfig(rockContext); } if (ranEFMigrations || anyPluginMigrations) { // If any migrations ran (version was likely updated) SendVersionUpdateNotifications(); ShowDebugTimingMessage("Send Version Update Notifications"); } // Start the message bus RockMessageBus.StartAsync().Wait(); var busTransportName = RockMessageBus.GetTransportName(); if (busTransportName.IsNullOrWhiteSpace()) { ShowDebugTimingMessage("Message Bus"); } else { ShowDebugTimingMessage($"Message Bus ({busTransportName})"); } // Start stage 1 of the web farm RockWebFarm.StartStage1(); ShowDebugTimingMessage("Web Farm (stage 1)"); RegisterHttpModules(); ShowDebugTimingMessage("Register HTTP Modules"); // Initialize the Lava engine. InitializeLava(); ShowDebugTimingMessage($"Initialize Lava Engine ({LavaService.CurrentEngineName})"); // setup and launch the jobs infrastructure if running under IIS bool runJobsInContext = Convert.ToBoolean(ConfigurationManager.AppSettings["RunJobsInIISContext"]); if (runJobsInContext) { StartJobScheduler(); ShowDebugTimingMessage("Start Job Scheduler"); } // Start stage 2 of the web farm RockWebFarm.StartStage2(); ShowDebugTimingMessage("Web Farm (stage 2)"); }
protected void btnRestart_Click(object sender, EventArgs e) { RockWebFarm.OnRestartRequested(CurrentPerson); RestartWebApplication(); }
/// <summary> /// Shows the mode where the user is only viewing an existing streak type /// </summary> private void ShowViewMode() { if (!IsViewMode()) { return; } var canEdit = CanEdit(); btnEdit.Visible = canEdit; pnlEditDetails.Visible = false; pnlViewDetails.Visible = true; HideSecondaryBlocks(false); // Load values from system settings var minPolling = RockWebFarm.GetLowerPollingLimitSeconds(); var maxPolling = RockWebFarm.GetUpperPollingLimitSeconds(); var minDifference = RockWebFarm.GetMinimumPollingDifferenceSeconds(); var pollingWait = RockWebFarm.GetMaxPollingWaitSeconds(); var maskedKey = SystemSettings.GetValue(SystemSetting.WEBFARM_KEY).Masked(); if (maskedKey.IsNullOrWhiteSpace()) { maskedKey = "None"; } // Build the description list with the values var descriptionList = new DescriptionList(); descriptionList.Add("Key", string.Format("{0}", maskedKey)); descriptionList.Add("Min Polling Limit", string.Format("{0} seconds", minPolling)); descriptionList.Add("Max Polling Limit", string.Format("{0} seconds", maxPolling)); descriptionList.Add("Min Polling Difference", string.Format("{0} seconds", minDifference)); descriptionList.Add("Max Polling Wait", string.Format("{0} seconds", pollingWait)); var unresponsiveMinutes = 10; var unresponsiveDateTime = RockDateTime.Now.AddMinutes(0 - unresponsiveMinutes); // Bind the grid data view models using (var rockContext = new RockContext()) { var webFarmNodeService = new WebFarmNodeService(rockContext); var webFarmNodeMetricService = new WebFarmNodeMetricService(rockContext); var viewModels = webFarmNodeService.Queryable() .AsNoTracking() .Select(wfn => new WebFarmNodeService.NodeViewModel { PollingIntervalSeconds = wfn.CurrentLeadershipPollingIntervalSeconds, IsJobRunner = wfn.IsCurrentJobRunner, IsActive = wfn.IsActive, IsUnresponsive = wfn.IsActive && !wfn.StoppedDateTime.HasValue && wfn.LastSeenDateTime < unresponsiveDateTime, IsLeader = wfn.IsLeader, NodeName = wfn.NodeName, LastSeen = wfn.LastSeenDateTime, Id = wfn.Id, Metrics = wfn.WebFarmNodeMetrics .Where(wfnm => wfnm.MetricType == WebFarmNodeMetric.TypeOfMetric.CpuUsagePercent && wfnm.MetricValueDateTime >= ChartMinDate && wfnm.MetricValueDateTime <= _chartMaxDate) .Select(wfnm => new WebFarmNodeMetricService.MetricViewModel { MetricValueDateTime = wfnm.MetricValueDateTime, MetricValue = wfnm.MetricValue }) .ToList() }) .ToList(); rNodes.DataSource = viewModels.OrderBy(n => n.NodeName); rNodes.DataBind(); } lDescription.Text = descriptionList.Html; }