-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorker.cs
40 lines (36 loc) · 1.18 KB
/
Worker.cs
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 Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using DataExchangeWorkerService.Services;
namespace DataExchangeWorkerService
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
private readonly EtlProcessor _etlProcessor;
public Worker(ILogger<Worker> logger, EtlProcessor etlProcessor)
{
_logger = logger;
_etlProcessor = etlProcessor;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.UtcNow);
try
{
_etlProcessor.DoWork();
}
catch (Exception e)
{
_logger.LogCritical($"Something went wrong, Exception message: {e.Message}");
Console.WriteLine(e);
}
await Task.Delay(1000 * 60 * 5, stoppingToken);
}
}
}
}