Hangfire没有活动服务器

时间:2015-06-21 23:05:36

标签: asp.net asp.net-mvc hangfire

发布ASP MVC应用程序后,Hangfire Dashboard表示它没有活动服务器。试图重新启动,重建,删除数据库中的Hangfire表 - 没有成功。 OWIN启动课程:

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            app.MapSignalR();
            GlobalConfiguration.Configuration
            .UseSqlServerStorage(@"HangfireStorage");

            var options = new BackgroundJobServerOptions
            {
                Queues = new[] { "critical", "default" }
            };

            app.UseHangfireServer(options);

            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                AuthorizationFilters = new[] { new MyRestrictiveAuthorizationFilter() }
            });
            var hangfireUpdatingCron = ConfigurationManager.AppSettings["HangfireUpdatingPlayersCron"];
            var hangfireUpdatingLeagueMatchesCron = ConfigurationManager.AppSettings["HangfireUpdatingLeagueMatchesCron"];
            BackgroundJob.Enqueue(() => SteamParser.ResetAllUpdatings());
            BackgroundJob.Enqueue(() => SteamParser.UpdateAllPlayers());
            RecurringJob.AddOrUpdate(() => SteamParser.UpdateAllPlayers(), hangfireUpdatingCron);
            RecurringJob.AddOrUpdate(() => SteamParser.UpdateLeagueMatches(), hangfireUpdatingLeagueMatchesCron);
        }
    }

3 个答案:

答案 0 :(得分:2)

  你好!后台作业服务器实例现在(从1.5.0-beta1开始)使用   每个实例的基于GUID的唯一标识符,因此没有必要   设置任何魔术服务器名称。

参考:https://github.com/HangfireIO/Hangfire/issues/223

在hangfire授权问题之后,我的问题只是一段被遗忘的代码。

我忘了添加:

app.UseHangfireServer();

很明显,仪表板已初始化

app.UseHangfireDashboard('/hangfire', someOptions);

然而,服务器没有运行。

提出一个新的该死的问题(篝火......),所以要解决那个问题。

希望这有帮助。

答案 1 :(得分:1)

好的,现在为我工作。也许你的情况有类似的解决方案。从我的更新到issue

的释义

我的问题特别是我在同一个应用程序池中运行多个应用程序,所以默认的" machinename:PID"命名方案并不是唯一的。但每个应用程序都指向它自己的独立数据库。因此,在启动/部署方面存在竞争,并且只有一个应用程序声称单个BackgroundJobServer是自己的。但没有记录错误;一切都很好。

答案在docs:"由于默认值仅在进程级别上提供唯一性,因此如果要在同一进程内运行不同的服务器实例,则应手动处理它# 34;

但重要的是,这种情况包括在同一个应用程序池下运行的多个应用程序,这是一个单独的进程。

此外,当我尝试实现doc中建议的更改(设置唯一的BackgroundJobServerOptions.ServerName)时,由于this comment中提到的maxlength问题,它会出错。我的解决方案是使用比GUID更短的东西来实现唯一性。就我而言,我使用了应用程序的名称。

答案 2 :(得分:1)

这对我有帮助: 在OWIN Startup类中,我添加了带有ServerName的BackgroundJobServerOptions:

var options = new BackgroundJobServerOptions
            {
                Queues = new[] { "critical", "default" },
                 ServerName = "Hangfire:1"
            };