* Added checking of missing EdiCo based on EdiCoTranslate and send email every 30 minutes * Added Admin Scheduler view
32 lines
854 B
C#
32 lines
854 B
C#
using SytelineSaAppEfDataModel.Services;
|
|
|
|
namespace FaKrosnoApi.Services;
|
|
|
|
public class TimedHostedService(IServiceScopeFactory scopeFactory) : IHostedService, IDisposable
|
|
{
|
|
private Timer? _timer;
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(30));
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void DoWork(object? state)
|
|
{
|
|
using var scope = scopeFactory.CreateScope();
|
|
var scheduledJob = scope.ServiceProvider.GetRequiredService<IScheduleJobService>();
|
|
scheduledJob.ExecuteAsync();
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_timer?.Change(Timeout.Infinite, 0);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_timer?.Dispose();
|
|
}
|
|
} |