Skip to content

Commit

Permalink
feat: prevent duplicate time
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed Dec 5, 2023
1 parent c3bffb4 commit 66a78be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/NekoSpace.Toolkit.HostedServices/CronScheduledService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ private void RefreshTimer()

_timer.Stop();

var nextOccurrence = _cronExpr.GetNextOccurrence(DateTime.UtcNow);
var now = DateTime.UtcNow;
var nextOccurrence = _cronExpr.GetNextOccurrence(now);
if (nextOccurrence is not { } next)
{
Debug.WriteLine("No next occurrence.");
return;
}

var delay = next - DateTime.UtcNow;
var delay = next - now;

Debug.WriteLine($"Delay {delay}, next occurrence: {next.ToLocalTime()}");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Authors>bsdayo</Authors>
<Description>Utilities for building Hosted Service for .NET Generic Host (or ASP.NET Core) applications.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit 66a78be

Please sign in to comment.