Files
FA_WEB/FaKrosnoApi/Services/TimedHostedService.cs
Piotr Kus c0fed5b3ec * Maintain FaKrosno api to handle Hangfire
* Added checking of missing EdiCo based on EdiCoTranslate and send email every 30 minutes
* Added Admin Scheduler view
2025-02-14 08:46:56 +01:00

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();
}
}