当 Hangfire 与我的 Web 应用程序在同一个应用程序池上运行时,我的性能受到了很大的影响,而且我们的网站变得非常慢,CPU 始终处于 96%。我查看了 Hangfire 文档,有一种方法可以将 Hangfire 作为控制台或 Windows 服务单独运行。但是,我不明白如何实现这一点并仍然获得仪表板。我已经创建了此链接中所述的服务Here https://docs.hangfire.io/en/latest/background-processing/processing-jobs-in-windows-service.html。以下是当前设置
Startup
[assembly: OwinStartup(typeof(MyProject.FrontEnd.Startup))]
namespace MyProject.FrontEnd
{
/// <summary>
///
/// </summary>
public class Startup
{
/// <summary>
///
/// </summary>
/// <param name="app"></param>
public void Configuration(IAppBuilder app)
{
app.UseHangfireAspNet(GetHangfireServers);
app.UseHangfireDashboard();
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.Use<RememberMeTokenMiddleware>();
.........
}
private IEnumerable<IDisposable> GetHangfireServers()
{
GlobalConfiguration.Configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage("eCertDb");
yield return new BackgroundJobServer();
}
如果我只评论app.UseHangfireAspNet(GetHangfireServers);
仪表板和应用程序中断。我收到错误
JobStorage.Current 属性值尚未初始化。你必须
在使用 Hangfire 客户端或服务器 API 之前设置它
。如果我评论app.UseHangfireDashboard();
,现在只要我实施了 Hangfire,它就会崩溃,例如在我的业务层
BackgroundJob.Enqueue<DocumentServiceWorker>(_ => _.PublishDocument(application.ApplicationReferenceNo, false));
问题是如果hangfire 在不同的进程中运行,我如何在主应用程序中仍然有上述调用?如果我将 Hangfire 作为 Windows 服务运行,我仍然如何获取仪表板,我是否需要单独的站点?