Is possible for Hangfire database to be called only when one hits /hangfire (or custom /hangfire-address)?
Currently, I call the database on startup (services.AddHangfire(o => o.UseSqlServerStorage....etc), so if the Hangfire database is down or off, the whole app won't even load.
If this isn't possible already, I believe it would be a great feature for Hangfire to only fire when browsed to its address.
How would you in practice imagine that should work? Hangfire uses the database like, _all the time_, whether you access the dashboard or not, for calculating what jobs to run when.
What you're asking for is basically if Hangfire can't load, then just skip the use of Hangfire alltogether, which you can handle yourself by putting services.AddHangfire(o => o.UseSqlServerStorage... insiide a tryu-catch block and silently continue on errors.
Aha....makes complete sense, thank you the explanation.
@cindro, the database is checked on startup only if automatic migrations are enabled (by default), and you can opt out this behavior:
o.UseSqlServerStorage("connection_string", new SqlServerStorageOptions
{
PrepareSchemaIfNecessary = false
});
But if you are calling to other Hangfire methods like RecurringJob.* or BackgroundJob.*, then your database will be involved anyway – for creating background jobs.
Most helpful comment
@cindro, the database is checked on startup only if automatic migrations are enabled (by default), and you can opt out this behavior:
But if you are calling to other Hangfire methods like
RecurringJob.*orBackgroundJob.*, then your database will be involved anyway – for creating background jobs.