Amy Amy - 5 months ago 17
C# Question

Hangfire recurring job never triggers?

I expect the following code to execute

UpdateSearchIndex()
, yet it doesn't. The
Start()
method is getting executed without a problem. Nothing is written to my logs.

This is running in an IIS-hosted OWIN process. What am I doing wrong? Why doesn't
UpdateSearchIndex()
execute?

public static class ScheduleUpdates
{
public static void Start()
{
GlobalConfiguration.Configuration
.UseNLogLogProvider()
.UseMemoryStorage();

RecurringJob.AddOrUpdate("update-search-idx", () => UpdateSearchIndex(), Cron.Minutely);
RecurringJob.Trigger("update-search-idx");
}

public static void UpdateSearchIndex()
{
Debugger.Break();
}
}

Answer Source

Looks like youre not starting Hangfire. In your Owin startup class you should call UseHangfireServer() extension method on IAppBuilder (http://docs.hangfire.io/en/latest/quick-start.html)