I have just started using Quartz on my asp.net core web API project but I can't figure out how to access my database/context on my quartz class that implements IJob
, when I try to add the context to my constructor the job doesn't get scheduled anymore and doesn't run at all, although it should run every 5 seconds, here is my old job class which works fine and get scheduled to run fine every 5 seconds:
class BatchJobCheckContract : IJob
{
public async Task Execute(IJobExecutionContext context)
{
var msg = "\n -- Contract checking job executed at : " + DateTime.Now.ToString();
Debug.WriteLine(msg);
}
}
and here is how I changed it to access my database but doesn't work anymore :
class BatchJobCheckContract : IJob
{
private readonly RHPDbContext _context;
public BatchJobCheckContract(RHPDbContext context)
{
_context = context;
}
public async Task Execute(IJobExecutionContext context)
{
var msg = "\n -- Contract checking job executed at : " + DateTime.Now.ToString();
Debug.WriteLine(msg);
var workers = await _context.Workers
.Include(w => w.ContactInformationGroup.ContactInformations)
.Include(w => w.AddressGroup.Addresses)
.Include(w => w.CalculationProfilGroup.CalculationProfil)
.Include(w => w.Contracts)
.Include(w => w.Absences).ThenInclude(x => x.AbsenceGroup)
.ToListAsync();
Debug.WriteLine(workers.Count);
}
}
what am I doing wrong? how can I access the context the right way?