【问题标题】:Hangfire in WebApi with Autofac: Job not running使用 Autofac 在 WebApi 中的 Hangfire:作业未运行
【发布时间】:2017-02-04 17:04:44
【问题描述】:

我在我的 WebApi 应用程序中使用 Hangfire 和 Hangfire.MemoryStorage

我在自己的 startup.cs 中配置了 Hangfire:

 Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
 app.UseHangfireServer();

我尝试在控制器中使用作业激活

var jobId = BackgroundJob.Schedule(
                    () => ForceMissionEmail(mission.Guid),
                    TimeSpan.FromSeconds(10));

代码运行没有错误,但 10 秒后没有调用 ForceMissionEmail 方法。

【问题讨论】:

  • 尝试在 IBackgroundJobClient 上使用 Enqueue 方法来测试 Hangfire 是否设置正确。
  • enqueue 不会抛出错误,但我的方法没有被调用 var jobId = BackgroundJob.Enqueue(() => ForceMissionEmail(mission.Guid));
  • 我认为你应该尝试添加一个控制台记录器docs.hangfire.io/en/latest/configuration/…

标签: c# asp.net-web-api owin autofac hangfire


【解决方案1】:

使用 Hangfire.Autofac Nuget 包和以下代码行解决了我的问题

IContainer container = AutoFacConfig.Register(config, app);
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(container);
Hangfire.GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireServer();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 2018-08-01
    • 2021-11-25
    相关资源
    最近更新 更多