'My Hangfire job fires, but nothing happens and there are no errors

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 works 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 am not sure why the Hangfire job doesn't work. In the Hangfire dashboard, I don't see any errors when I manually trigger it. It runs successfully. But the emails are not sent out.

Is there something wrong with Hangfire?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source