-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRefreshAnnouncementsFunction.cs
More file actions
40 lines (33 loc) · 1.29 KB
/
RefreshAnnouncementsFunction.cs
File metadata and controls
40 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using ByteSync.Common.Business.Announcements;
using ByteSync.ServerCommon.Interfaces.Loaders;
using ByteSync.ServerCommon.Interfaces.Repositories;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace ByteSync.Functions.Timer;
public class RefreshAnnouncementsFunction
{
private readonly IAnnouncementsLoader _loader;
private readonly IAnnouncementRepository _repository;
private readonly ILogger<RefreshAnnouncementsFunction> _logger;
public RefreshAnnouncementsFunction(IAnnouncementsLoader loader, IAnnouncementRepository repository,
ILogger<RefreshAnnouncementsFunction> logger)
{
_loader = loader;
_repository = repository;
_logger = logger;
}
[Function("RefreshAnnouncementsFunction")]
public async Task<int> RunAsync([TimerTrigger("0 0 */2 * * *"
#if DEBUG
, RunOnStartup = true
#endif
)] TimerInfo timerInfo)
{
var currentUtcTime = DateTime.UtcNow;
_logger.LogInformation("Refreshing announcements at: {Now}", currentUtcTime);
var announcements = await _loader.Load();
var validAnnouncements = announcements.Where(d => d.EndDate > currentUtcTime).ToList();
await _repository.SaveAll(validAnnouncements);
return validAnnouncements.Count;
}
}