* Maintain FaKrosno api to handle Hangfire
* Added checking of missing EdiCo based on EdiCoTranslate and send email every 30 minutes * Added Admin Scheduler view
This commit is contained in:
32
FaKrosnoApi/Services/TimedHostedService.cs
Normal file
32
FaKrosnoApi/Services/TimedHostedService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user