Skip to content

Commit

Permalink
fix: make sure refresh-worker executes next on full hour of day
Browse files Browse the repository at this point in the history
  • Loading branch information
alsami committed Jan 9, 2021
1 parent c2d977b commit 532f868
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Covid19Api.Worker/DataRefreshWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ private DateTime CalculateInitialExecutionTime()
private DateTime CalculateNextRun()
{
var nextExecution = DateTime.UtcNow.AddHours(4);

if (nextExecution.Day != DateTime.UtcNow.Day)
{
nextExecution = DateTime.UtcNow.Date.AddDays(1);
}

var hourDiffTillNextDay = 24 - nextExecution.Hour;

if (hourDiffTillNextDay <= 4)
{
nextExecution = nextExecution.AddHours(hourDiffTillNextDay - 1);
}


this.logger.LogInformation("Next refresh run {nextRun}", nextExecution.ToString("O"));
return nextExecution;
}
Expand Down

0 comments on commit 532f868

Please sign in to comment.