Ignore if no storage on startup

redis
Tags: #<Tag:0x00007f499bbd9660>

#1

Hi, how can I disable Hangfire (cancel or ignore services.AddHangfire(...) and services.AddHangfireServer(...)) if storage connection (to Redis in this case) cannot be established on startup of a .NET Core web app.

At the moment, it throws an error: InvalidOperationException: JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API., if Redis was unavailable or down for any reason.


#2

So, adding abortConnect=false to Redis connection string doesn’t raise an error on startup if Redis is unavailable, but a subsequent call to RecurringJob.AddOrUpdate throws an error: RedisConnectionException: No connection is available to service this operation.

Any way to avoid this to retry Redis connection in the background, and add jobs only once when connected?


#3

Unless I’m not understanding the severity of the problem, this sounds as simple as if(redis.isHealthy()) {AddHangfireServer()}