Best practices or guidelines for code being setup for Hangfire jobs

Are there any best practices around code being queued? Lets say if I have a method like this crashing, would the worker handle the crash and re-queue the job?

public void EnqueuedMethod(int someId)
{
   //no exception handling here
}

If its hangfire scheduled method is internally calling a method which is async, should I configure the awaitable to false?

    private async Task<NotificationOutcome> Send(string json, string[] tags)
    {
        return await Hubclient.SendNativeNotificationAsync(json, tags)
                              .ConfigureAwait(false);
    }

I’m looking for some guidelines, we are experiencing once in a while Hangfire worker lockups and I do think it is due to our code not being setup correctly to run inside the hangfire process.

Another topic is we have an EF datacontect which is thread scoped/instantiated. Would this be a wise thing to run inside a enqued method? Or since the workers are running forever, would this mean this datacontext is created once per thread and lives forever?

1 Like