I have a ASP.NET MVC Application that works as Hangfire client - it enqueues different jobs. I am using SqlServerJobStorage
for Hangfire usage.
For now i am working on a scenario when there is no connection to Hangfire Database, and somewhere in the future connection is being instantiated.
The goal is that my ASP.NET MVC Application should keep working before this moment. After connection restores it should start to enqueue jobs.
So application will throw an exception in Global.asax
:
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage("EshopServiceHangfire");
Moreover all job enqueues will also throw exceptions:
BackgroundJob.Enqueue<ISomeClass>(x => x.DoSomethingGreat(JobCancellationToken.Null));
I put the row from Global.asax
in a try/catch block, so it will not throw.
When somebody enqueue job, i want to check JobStorage.Current
and if it is not initialized, i`l try to init it again with the same code:
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage("EshopServiceHangfire");
Does anybody knows a way to do this? Documentation has no information about this.
Something like Hangfire.GlobalConfiguration.JobStorage.IsInitialized
?
Catching exception from Job enqueue also is a way, but i don`t like it, because it throws non specific
InvalidOperationException: JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.
Much appreciated for those who have read up to this place)