private static void UpdateLoadGeneratingUnits() { // Instead, just queue a total LGU update BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunLoadGeneratingUnitRefreshJob(null)); // And follow it up with an HRU update BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunHRURefreshJob()); }
private void ExecuteModelIfNeeded(bool wereAnyLoadGeneratingUnitsToUpdate) { var updatedRegionalSubbasins = DbContext.RegionalSubbasins.Where(x => x.LastUpdate != null).ToList(); var lastRegionalSubbasinUpdateDate = updatedRegionalSubbasins.Any() ? updatedRegionalSubbasins.Max(x => x.LastUpdate.Value) : DateTime.MinValue; var updatedNereidResults = DbContext.NereidResults.Where(x => x.LastUpdate != null).ToList(); var lastNereidResultUpdateDate = updatedNereidResults.Any() ? updatedNereidResults.Max(x => x.LastUpdate.Value) : DateTime.MinValue; if (wereAnyLoadGeneratingUnitsToUpdate) { // if there was any work done, check if all the HRUs are populated and if so blast off with a new solve. DbContext.LoadGeneratingUnits.Load(); // don't die if it takes longer than 30 seconds for this next query to come back DbContext.Database.CommandTimeout = 600; var loadGeneratingUnitsMissingHrus = GetLoadGeneratingUnitsToUpdate(DbContext).Any(); if (!loadGeneratingUnitsMissingHrus) { if (lastRegionalSubbasinUpdateDate > lastNereidResultUpdateDate) { BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunTotalNetworkSolve()); } else if (DbContext.DirtyModelNodes.Any()) { BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunDeltaSolve()); } } } else { // if the job woke up and went immediately to sleep, then all HRUs are populated. if (lastRegionalSubbasinUpdateDate > lastNereidResultUpdateDate) { BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunTotalNetworkSolve()); } else if (DbContext.DirtyModelNodes.Any()) { BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunDeltaSolve()); } } }
public static void RunRefresh(DatabaseEntities dbContext, Person person, bool queueLguRefresh) { dbContext.RegionalSubbasinStagings.DeleteRegionalSubbasinStaging(dbContext.RegionalSubbasinStagings.ToList()); dbContext.SaveChanges(person); var newRegionalSubbasinFeatureCollection = RetrieveFeatureCollectionFromArcServer(); ThrowIfCatchIdnNotUnique(newRegionalSubbasinFeatureCollection); StageFeatureCollection(newRegionalSubbasinFeatureCollection); ThrowIfDownstreamInvalid(dbContext); DeleteLoadGeneratingUnits(dbContext); MergeAndReproject(dbContext, person); RefreshCentralizedDelineations(dbContext, person); BackgroundJob.Enqueue(() => ScheduledBackgroundJobLaunchHelper.RunDelineationDiscrepancyCheckerJob()); if (queueLguRefresh) { UpdateLoadGeneratingUnits(); } }
/// <summary> /// Set up the jobs particular to this application /// </summary> private static void ConfigureScheduledBackgroundJobs() { var recurringJobIds = new List <string>(); AddRecurringJob(TrashGeneratingUnitRefreshScheduledBackgroundJob.JobName, () => ScheduledBackgroundJobLaunchHelper.RunTrashGeneratingUnitRefreshScheduledBackgroundJob(), MakeDailyUtcCronJobStringFromLocalTime(22, 30), recurringJobIds); AddRecurringJob("Refresh RSBs", () => ScheduledBackgroundJobLaunchHelper.RunRegionalSubbasinRefreshBackgroundJob(1122, true), MakeWeeklyUtcCronJobStringFromLocalTime(1, 30, DayOfWeek.Saturday), recurringJobIds); AddRecurringJob(HRURefreshBackgroundJob.JobName, () => ScheduledBackgroundJobLaunchHelper.RunHRURefreshJob(), "*/30 * * * *", recurringJobIds); // todo: remove this after the WQIP meeting. It ensures that data is accurate every morning for the trade of disguising bugs that happen during the day. AddRecurringJob(TotalNetworkSolveJob.JobName, () => ScheduledBackgroundJobLaunchHelper.RunTotalNetworkSolve(), MakeDailyUtcCronJobStringFromLocalTime(1, 0), recurringJobIds); // Remove any jobs we haven't explicity scheduled RemoveExtraneousJobs(recurringJobIds); }