Using HangFire in Azure Web App


#1

I am using Hangfire as part of an ASP.NET MVC Website.

When I run the site locally, Hangfire works as expected. However, when I run Hangfire in the Production Environment (In Azure as a Web App), I am not able to access the Dashboard nor does it seem like the automatic jobs are running.

I initialize Hangfire entirely from the Status.cs:

public void Configuration(IAppBuilder Application)
{
      Application.CreatePerOwinContext<RepositoryManager>((x, y) => new RepositoryManager(new SiteDatabase(), x, y));
      Application.UseCookieAuthentication(new CookieAuthenticationOptions
      {
           CookieName = "Authentication",
           LoginPath = new PathString("/login"),
           AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
           Provider = new CookieAuthenticationProvider
           {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager, User, int>(
                     validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (Manager, User) => User.GenerateClaimsAsync(Manager),
                     getUserIdCallback: (Claim) => int.Parse(Claim.GetUserId()))
           }
});

Application.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

GlobalConfiguration.Configuration
    .UseSqlServerStorage("platform_batch", new SqlServerStorageOptions { SchemaName = "dbo" })
    .UseDashboardMetric(SqlServerStorage.ActiveConnections)
    .UseDashboardMetric(SqlServerStorage.TotalConnections)
    .UseDashboardMetric(DashboardMetrics.FailedCount)
    .UseLogProvider<BatchLogProvider>(new BatchLogProvider())
    .UseFilter<AutomaticRetryAttribute>(new AutomaticRetryAttribute { Attempts = 0 });

Application.UseHangfireDashboard("/dashboard/global/batches",
    new DashboardOptions
    {
        AppPath = "/dashboard/global/overview",
        Authorization = new IDashboardAuthorizationFilter[] { new ContextRootAttribute(), new ContextStatusAttribute(StatusLevel.Owner) },
    });
    Application.UseHangfireServer(new BackgroundJobServerOptions { ServerName = Global.Property.Deployment.Environment.ToString() });

    RecurringJob.AddOrUpdate<BatchMinute>(x => x.Begin(), Cron.Minutely());
    RecurringJob.AddOrUpdate<BatchDay>(x => x.Begin(), Cron.Daily(2));
}

Again, this method works perfectly fine locally and in our staging environment (which runs on IIS), but doesn’t seem to work in our Azure Production Environment. Any ideas?