Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Hangfire problem: JobStorage.Current property value #3753


User avatar
0
cangunaydin created

Hello, I am trying to implement a recurring job. It is working fine with background worker class in abp i followed the doc over here <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers">https://aspnetboilerplate.com/Pages/Doc ... nd-Workers</a>

now i wanted to implement this with hangfire. I looked at couple of questions related with this in the forum. #2645

i followed the same steps in this thread but i couldn't manage to make it work. Basically what i have done is uncomment some lines in startup to tell the hangfire to use the sql. Then i have added my recurring job in post initialize method of the web module.

WebHostModule code.

public override void PreInitialize()
        {
            Configuration.Modules.AbpWebCommon().MultiTenancy.DomainFormat = _appConfiguration["App:ServerRootAddress"] ?? "http://localhost:22742/";
            GlobalConfiguration.Configuration.UseActivator(new WindsorHangFireJobActivator());
        }
        public override void PostInitialize()
        {
            var offerManager = IocManager.Resolve<IOfferManager>();
            RecurringJob.AddOrUpdate("CampaignReminder",() => offerManager.SendRemindersForCampaigns(), Cron.Minutely);
            //var workManager = IocManager.Resolve<IBackgroundWorkerManager>();
            //workManager.Add(IocManager.Resolve<CampaignReminder>());
        }

Startup.

public IServiceProvider ConfigureServices(IServiceCollection services)
        {
//other codes.
 //Hangfire (Enable to use Hangfire instead of default job manager)
            services.AddHangfire(config =>
            {
                config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
            });
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {

//other codes
 //Hangfire dashboard &server(Enable to use Hangfire instead of default job manager)
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                //Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
            });
            app.UseHangfireServer();
}

WebCoreModule

public override void PreInitialize()
        {
//other codes

//Uncomment this line to use Hangfire instead of default background job manager (remember also to uncomment related lines in Startup.cs file(s)).
            Configuration.BackgroundJobs.UseHangfire();
}

when the application starts i always get an error "JobStorage.Current property value has not been initialized". As i read from the stackoverflow they are always pointing out this code

services.AddHangfire(config =>
            {
                config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
            });

which is fired at startup and in post initialize there is no JobStorage.Current value. What am i missing over here? Any ideas?


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @cangunaydin,

    Sorry for the late response, have you solved your issue ?

  • User Avatar
    0
    cangunaydin created

    Hello @ismcagdas No i couldn't figure it out. It is giving me the same error whatever i do. Do you have any ideas?

    By the way i am using v4.0 with angular2 & asp.net core .Net Framework v4.6

  • User Avatar
    0
    cangunaydin created

    Hello again @ismcagdas, i fixed the problem by adding this line to startup.

    //Hangfire (Enable to use Hangfire instead of default job manager)
                services.AddHangfire(config =>
                {
                    config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
                });
                JobStorage.Current = new SqlServerStorage(_appConfiguration.GetConnectionString("Default"));
    

    But what i don't understand is why it doesn't configure the current jobstorage when i say it in the above line. And i have never seen in somebody else this problem. Do you have any explanation for it @ismcagdas?

    Also i want to ask, from angular project how can i define a link to show the user the hangfire dashboard? should i direct the user to the server side link or what is the proper way to do that?

    Thanks in advance,

  • User Avatar
    0
    cangunaydin created

    And if i redirect the users from angular app to the server link (hangfire dashboard link), authorization filter is becoming a problem. Is there any work around for this? Did you implement sth regarding to display the hangfire dashboard from an angular link?

    Also how can i authorize myself to the server app. from angular for hangfire? i can call the swagger api methods of course but how to create session with authorization and redirect the user to the hangfire dashboard page?

  • User Avatar
    0
    bilalhaidar created

    Hello gentlemen, I am also facing problem trying to configure Hangfire. It only worked after I add this line too:

    JobStorage.Current = new SqlServerStorage(_appConfiguration.GetConnectionString("Default"));
    

    I thought that was already configured when this line runs:

    services.AddHangfire(config =>
                {
                    config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
                });
    

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @cangunaydin,

    Actually, we didn't work on showing hangfire dashboard in angular 4 version. Maybe you should check hangfire's documentation if it supports token based auth nad how to handle it.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    This could help: <a class="postlink" href="http://docs.hangfire.io/en/latest/configuration/using-dashboard.html">http://docs.hangfire.io/en/latest/confi ... board.html</a>

    It says, with ASP.NET Core, you can create a new class that implements IDashboardAuthorizationFilter. Inside that code you can check on permissions I believe to see if you can access or not.

  • User Avatar
    0
    cangunaydin created

    Hello guys, Thank you for the answers i will check it out.