/// <summary> /// Performs several actions aimed at cleaning the database. /// </summary> /// <returns></returns> public async Task Run(HangfireRecurringCleanerViewModel viewModel) { // Stop the ongoing long running analyses. await StopAnalyses(numberOfDays : 7); // Delete the ongoing long running analyses. await ForceStopAnalyses(numberOfDays : 7, numberOfDaysLeft : 1); // Alert about the items close to deletion. await AlertDelete(scheme : viewModel.Scheme, host : new HostString(viewModel.HostValue), numberOfDays : 31, numberOfDaysLeft : 7); // Delete the items. await DeleteNetworks(numberOfDays : 31); await DeleteAnalyses(numberOfDays : 31); }
public IActionResult OnPostResetHangfireRecurrentJobs() { // Delete any existing recurring tasks of cleaning the database. RecurringJob.RemoveIfExists(nameof(IHangfireRecurringJobRunner)); // Define the view model for the recurring task of cleaning the database. var viewModel = new HangfireRecurringCleanerViewModel { Scheme = HttpContext.Request.Scheme, HostValue = HttpContext.Request.Host.Value }; // Create a daily recurring Hangfire task of cleaning the database. RecurringJob.AddOrUpdate <IHangfireRecurringJobRunner>(nameof(IHangfireRecurringJobRunner), item => item.Run(viewModel), Cron.Daily()); // Display a message. TempData["StatusMessage"] = "Success: The Hangfire recurrent jobs have been successfully reset. You can view more details on the Hangfire dasboard."; // Redirect to the page. return(RedirectToPage()); }