我在WebApi应用程序中将Hangfire与Hangfire.MemoryStorage
一起使用。
我在猫头鹰startup.cs
中配置了杭火:
Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireServer();
我尝试在控制器中使用作业激活
var jobId = BackgroundJob.Schedule(
() => ForceMissionEmail(mission.Guid),
TimeSpan.FromSeconds(10));
代码运行没有错误,但 10 秒后不会调用 ForceMissionEmail
方法。
使用 Hangfire.Autofac Nuget 包和以下代码行解决了我的问题
IContainer container = AutoFacConfig.Register(config, app);
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(container);
Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireServer();