38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Brizco.Domain.Entities.Shifts;
|
|
using Microsoft.Extensions.Logging;
|
|
using Quartz;
|
|
|
|
namespace Brizco.Core.QuartzServices;
|
|
|
|
public class NotificationScheduledJob : IJob
|
|
{
|
|
private readonly ILogger<NotificationScheduledJob> _logger;
|
|
private readonly IScheduler _scheduler;
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public NotificationScheduledJob(ILogger<NotificationScheduledJob> logger,IScheduler scheduler,IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_logger = logger;
|
|
_scheduler = scheduler;
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
{
|
|
var currentShiftPlans = await _repositoryWrapper.SetRepository<ShiftPlan>()
|
|
.TableNoTracking
|
|
.Where(s => s.PlanFor.Date >= DateTime.Today.Date)
|
|
.ToListAsync();
|
|
|
|
IJobDetail job = JobBuilder.Create<NotificationScheduledJob>()
|
|
.WithIdentity("NotificationJob", "notification")
|
|
.Build();
|
|
ITrigger trigger = TriggerBuilder.Create()
|
|
.WithIdentity("NotificationJobTrigger", "notification")
|
|
.StartNow()
|
|
.Build();
|
|
var offset = _scheduler.ScheduleJob(job, trigger);
|
|
|
|
_logger.LogInformation($"Notification Job Done At : {DateTime.Now}");
|
|
}
|
|
} |