Search code examples
c#entity-frameworkhangfire

Jobs not being executed when methods contain database interaction


I have a recurring job: ImportJob.cs containing the following code:

[AutomaticRetry(Attempts = 0)]
[DisableConcurrentExecution(5)]
// ReSharper disable once UnusedMember.Global
public class ImportJob : IRecurringJob
{
    public void Execute(PerformContext context)
    {
        context.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} Starting import job...");

        using (AuthenticationEntities db = new AuthenticationEntities())
        {
            context.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} Counting current login events...");
            int loginevents = db.LoginEvents.Count();
            context.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} Found {loginevents} login events...");
        }
        context.WriteLine($"{DateTime.Now:yyyy/MM/dd HH:mm:ss} Finished import job...");
    }
}

The job is being queued, but its never completed (executed even?). Im not sure why its not being executed.

Im using the Hangfire.RecurringJobExtensions package to configure the jobs from a jobs.json. Im using a dbcontext (EF6 db-first .edmx) from a shared project, which just works fine in the rest of the application.


Solution

  • I made a basic mistake by changing the queue of the job, but never configured the server to process the different than default queue...