Hangfire has no active servers

7.2k views Asked by At

After publishing ASP MVC application, Hangfire Dashboard says, that it has no active servers. Tried to restart, rebuild, remove Hangfire's tables in DB - no success. OWIN Startup class:

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

There are 3 answers

0
CrazyPyro On BEST ANSWER

Ok, working for me now. Perhaps your situation has a similar solution. Paraphrasing from my update to that issue:

My problem was specifically that I was running multiple applications in the same app pool, so the default "machinename:PID" naming scheme was not unique. But each app was pointed to its own separate database. So there was a race on startup/deploy and only one of the apps got to claim the single BackgroundJobServer as its own. But no errors logged; everything looked fine.

The answer is in the docs: "Since the defaults values provide uniqueness only on a process level, you should to handle it manually, if you want to run different server instances inside the same process"

But the important point is that this situation includes multiple applications running under the same app pool, which is a single process.

Furthermore, when I attempted to implement the change suggested in the doc (setting a unique BackgroundJobServerOptions.ServerName), it errored out due to the maxlength problem mentioned in this comment. My solution was to use something shorter than a GUID for uniqueness. In my case, I used the application's name.

1
egorgrushin On

This helped to me: In OWIN Startup class I've added BackgroundJobServerOptions with ServerName:

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

Hi there! Background job server instances now (since 1.5.0-beta1) use GUID-based unique identifiers for each instance, so there is no need to set any magic server names.

Ref: https://github.com/HangfireIO/Hangfire/issues/223

My issue was simply a forgotten line of code after an authorization problem with hangfire.

I just forgot to add:

app.UseHangfireServer();

So obviously the dashboard was initialized

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

However the server was not running.

Coming up with a new damn problem(hangfire...), so gonna tackle that one.

Hope this helps.