Skip to content

Commit 2438279

Browse files
committed
Check for scheduled posts on a minute base
1 parent e9b7e41 commit 2438279

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/LinkDotNet.Blog.Web/Features/BlogPostPublisher.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public BlogPostPublisher(IServiceProvider serviceProvider, ILogger<BlogPostPubli
2525

2626
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2727
{
28-
logger.LogInformation("BlogPostPublisher is starting.");
28+
logger.LogInformation("BlogPostPublisher is starting");
2929

30-
using var timer = new PeriodicTimer(TimeSpan.FromHours(1));
30+
using var timer = new PeriodicTimer(TimeSpan.FromMinutes(1));
3131

3232
while (!stoppingToken.IsCancellationRequested)
3333
{
@@ -36,12 +36,12 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3636
await timer.WaitForNextTickAsync(stoppingToken);
3737
}
3838

39-
logger.LogInformation("BlogPostPublisher is stopping.");
39+
logger.LogInformation("BlogPostPublisher is stopping");
4040
}
4141

4242
private async Task PublishScheduledBlogPostsAsync()
4343
{
44-
logger.LogInformation("Checking for scheduled blog posts.");
44+
logger.LogInformation("Checking for scheduled blog posts");
4545

4646
using var scope = serviceProvider.CreateScope();
4747
var repository = scope.ServiceProvider.GetRequiredService<IRepository<BlogPost>>();
@@ -58,11 +58,11 @@ private async Task PublishScheduledBlogPostsAsync()
5858

5959
private async Task<IPagedList<BlogPost>> GetScheduledBlogPostsAsync(IRepository<BlogPost> repository)
6060
{
61-
var now = DateTime.Now;
61+
var now = DateTime.UtcNow;
6262
var scheduledBlogPosts = await repository.GetAllAsync(
6363
filter: b => b.ScheduledPublishDate != null && b.ScheduledPublishDate <= now);
6464

65-
logger.LogInformation("Found {Count} scheduled blog posts.", scheduledBlogPosts.Count);
65+
logger.LogInformation("Found {Count} scheduled blog posts", scheduledBlogPosts.Count);
6666
return scheduledBlogPosts;
6767
}
6868

0 commit comments

Comments
 (0)