-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUpdateFromSessionizeBackgroundService.cs
More file actions
37 lines (30 loc) · 1.24 KB
/
UpdateFromSessionizeBackgroundService.cs
File metadata and controls
37 lines (30 loc) · 1.24 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
using PocketDDD.Server.Services;
namespace PocketDDD.Server.WebAPI;
public class UpdateFromSessionizeBackgroundService(
IServiceProvider services,
ILogger<UpdateFromSessionizeBackgroundService> logger)
: BackgroundService
{
private ILogger<UpdateFromSessionizeBackgroundService> Logger { get; } = logger;
private IServiceProvider Services { get; } = services;
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Logger.LogInformation("Update from Sessionize background task started.");
while (!stoppingToken.IsCancellationRequested)
{
Logger.LogInformation("About to update from Sessionize.");
try
{
using var scope = Services.CreateScope();
var sessionizeService = scope.ServiceProvider.GetRequiredService<SessionizeService>();
await sessionizeService.UpdateFromSessionize();
Logger.LogInformation("Update from Sessionize complete.");
}
catch (Exception e)
{
Logger.LogError(e, "Update from Sessionize failed.");
}
await Task.Delay(TimeSpan.FromMinutes(30), stoppingToken);
}
}
}