marcoCasamento / Hangfire.Redis.StackExchange

HangFire Redis storage based on original (and now unsupported) Hangfire.Redis but using lovely StackExchange.Redis client
Other
456 stars 109 forks source link

Example of OWIN setup #14

Closed mkchandler closed 8 years ago

mkchandler commented 9 years ago

I upgraded to the latest versions of Hangfire.Core and this library and am having a really hard time figuring out the new way to set up Hangfire with Redis. My previous code looked like this:

app.UseHangfireServer(config =>
{
    config.UseAuthorizationFilters();
    config.UseRedisStorage("host:port", 1);
    config.UseServer();
});

Hangfire now complains because the definition of UseHangfireServer has changed. I've tried following some of the documentation on Hangfire's site but none of it seems to work.

Can you post a sample of how we should be setting up Hangfire to use Redis?

Versions via NuGet HangFire.Core: 1.4.6 HangFire.Redis.StackExchange: 1.4.7

mkchandler commented 9 years ago

I've attempted changing to this:

var redis = new RedisStorage("host:port", new RedisStorageOptions { Db = 1 });
GlobalConfiguration.Configuration.UseStorage(redis);

app.UseHangfireDashboard();
app.UseHangfireServer();

But I cannot get it to work. I get the following exception:

[InvalidOperationException: JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.]
   Hangfire.JobStorage.get_Current() +170
   Hangfire.AppBuilderExtensions.UseHangfireDashboard(IAppBuilder builder, String pathMatch, DashboardOptions options) +21
marcoCasamento commented 9 years ago

That's pretty strange! I've just setup a web application with the packages:

 <package id="Hangfire.Core" version="1.4.6" targetFramework="net45" />
 <package id="HangFire.Redis.StackExchange" version="1.4.7" targetFramework="net45" />

and startup:

public void Configuration(IAppBuilder app)
        {
            var storage = new RedisStorage("localhost:6379, allowAdmin=true", new RedisStorageOptions {Db = 3 });
            GlobalConfiguration.Configuration.UseDashboardMetric(storage.GetDashboardMetricFromRedisInfo("Redis Version", RedisInfoKeys.redis_version));
            GlobalConfiguration.Configuration.UseDashboardMetric(storage.GetDashboardMetricFromRedisInfo("Used Memory", RedisInfoKeys.used_memory_human));
            GlobalConfiguration.Configuration.UseDashboardMetric(storage.GetDashboardMetricFromRedisInfo("Peak Memory", RedisInfoKeys.used_memory_peak_human));
            GlobalConfiguration.Configuration.UseStorage(storage);
            app.UseHangfireDashboard(string.Empty, new DashboardOptions() { AppPath="/", AuthorizationFilters=new IAuthorizationFilter[0]});
            app.UseHangfireServer();

        }

and it works smooth. What version of Hangfire.Core do you use ?

marcoCasamento commented 8 years ago

Any news on this ? Is it solved now ?

mkchandler commented 8 years ago

Sorry, I've been unexpectedly away from work and haven't had a chance to retest. Will do so as soon as I can. Thanks for the quick replies!

On Mon, Sep 14, 2015 at 3:01 AM Marco Casamento notifications@github.com wrote:

Any news on this ? Is it solved now ?

— Reply to this email directly or view it on GitHub https://github.com/marcoCasamento/Hangfire.Redis.StackExchange/issues/14#issuecomment-139990187 .

mkchandler commented 8 years ago

So it looks like this was being caused by something else, possibly something cached up in IIS. After coming back to it today, it is working... Ugh, hate when that happens :-) Thanks for your help and quick response.