Hangfire: Don't load DB on startup

Created on 4 Sep 2017  Â·  3Comments  Â·  Source: HangfireIO/Hangfire

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.

sql-server question

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:

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vikramjb picture vikramjb  Â·  3Comments

osmanrahimi picture osmanrahimi  Â·  3Comments

dbones picture dbones  Â·  3Comments

JvanderStad picture JvanderStad  Â·  3Comments

cottsak picture cottsak  Â·  3Comments