-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to disable Hangfire #18
Conversation
Nice one @stevetemple !! I'm on holiday for a few weeks but will have a look when I'm back. |
Just did a quick test for my Job Scheduler and it looks like this: public class JobsComposer : IComposer
{
private static string GetTiming(string timing, bool disabled)
{
return disabled ? Cron.Never() : timing;
}
public class HangfireSettings
{
public bool? Disabled { get; set; }
}
public void Compose(IUmbracoBuilder builder)
{
var settings = builder.Config.GetSection("Hangfire").Get<HangfireSettings>();
var hangfireDisabled = settings.Disabled.GetValueOrDefault(false);
RecurringJob.AddOrUpdate<ITestService>($"This is a test job", x =>
x.RunTestJob(null), GetTiming(Cron.Daily(), hangfireDisabled));
}
} The most important part is the If Hangfire is disabled, jobs are still scheduled but will never run, but can be ran manually. To not schedule any jobs, you could write it differently like this and then public void Compose(IUmbracoBuilder builder)
{
var settings = builder.Config.GetSection("Hangfire").Get<HangfireSettings>();
var hangfireDisabled = settings.Disabled.GetValueOrDefault(false);
if (!hangfireDisabled)
{
RecurringJob.AddOrUpdate<ITestService>($"This is a test job", x =>
x.RunTestJob(null), Cron.Daily());
}
} |
I thought you were on holiday 🤨 I'd just tweaked it, realised that it wouldn't let jobs be added, just want the server side of it turned off but all servers could schedule jobs just won't run them. Meant to open this as a draft as I was just pitching the idea |
Running this on a production website, where the front end servers are disabled, but backoffice server enabled, works well I would probably change the setting name to Hangfire:Server:Disabled as it's the server part that is disabled rather than anything else. The front end servers can still add tasks etc but they'll only be run on the backoffice server |
Sorry for the delay @stevetemple "Hangfire": {
"Server": {
"Disabled": true
}
} Additionally, you were hiding the dashboard on instances that were not a server, which turned into an infinite spinner, I think it's fine to show the dashboard even if the current machine is not a server. Merged in 622d88f and will be released in v3.1.0 in a few minutes. |
Cool, thanks Yeah we disable backoffice on front-end so that might just be our way of working |
Just thinking about an option to disable on certain environments, for example local dev, or front end servers in a load balanced environment