I’m having an issue where my Hangfire job is being fired, but nothing happens and there are no errors.
So in my Configure method within Startup.cs I configure the Hangfire job:
using (var context = new OspSpaceExplorerContext())
{
MissionComms msc = new MemailAlertingProcessor(context);
RecurringJob.AddOrUpdate("[CRITICAL] - Process OrbitTime Notices :: CRITICAL",
() => msc .ProcessOrbitTimeNotices(), Cron.Daily);
}
The method that the job fires is here. It sends out an email if certain conditions are met:
public void ProcessOrbitTimeNotices()
{
var alertDate = DateTime.Today;
var missions = _context.Mission
.Include(m => m.Commander)
.ToList();
foreach (var mission in missions)
{
var dateTrigger = (int)Math.Round((mission.MissionDate - alertDate).TotalDays);
switch (dateTrigger)
{
case 90:
_commService.SendCommsAlert(
mission,
mission.Commander, 0090);
break;
case 31:
_commService.SendCommsAlert(
mission,
mission.Commander, 0071);
break;
}
}
}
So when I manually trigger the Hangfire job, it runs and there no errors. But the emails are not being sent out. I made sure for testing, that the conditions are being met.
Just to make sure, I copied and pasted the code above into a controller.
When I hit the controller, it is working! The emails are sent out.
[HttpGet("ExpiringMissions")]
public List<Mission> ExpiringMissions()
{
... same code as above
}
I’ve tried deleting the job and letting it get created again by Hangfire, I’ve rebooted the server, I’ve recycled the app pool.
I honestly can’t think of anything else to do so I was hoping somewhere here could help.
Thanks!