diff --git a/Cultiv.Hangfire/HangfireComposer.cs b/Cultiv.Hangfire/HangfireComposer.cs index 686621c..5413f49 100644 --- a/Cultiv.Hangfire/HangfireComposer.cs +++ b/Cultiv.Hangfire/HangfireComposer.cs @@ -6,6 +6,7 @@ using Hangfire.Storage.SQLite; using Microsoft.AspNetCore.Builder; using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; @@ -17,9 +18,11 @@ namespace Cultiv.Hangfire; public class HangfireComposer : IComposer { - public void Compose(IUmbracoBuilder builder) - { - builder.ManifestFilters().Append(); + public void Compose(IUmbracoBuilder builder) + { + var settings = builder.Config.GetSection("Hangfire:Server").Get(); + + builder.ManifestFilters().Append(); var provider = builder.Config.GetConnectionStringProviderName(Umbraco.Cms.Core.Constants.System.UmbracoConnectionName); @@ -40,12 +43,15 @@ public void Compose(IUmbracoBuilder builder) .UseRecommendedSerializerSettings() .UseConsole(); }); - - // Run the required server so your queued jobs will get executed - builder.Services.AddHangfireServer(); - AddAuthorizedUmbracoDashboard(builder); + if (!settings.Disabled.GetValueOrDefault(false)) + { + // Run the required server so your queued jobs will get executed + builder.Services.AddHangfireServer(); + } + AddAuthorizedUmbracoDashboard(builder); + return; } @@ -86,9 +92,12 @@ public void Compose(IUmbracoBuilder builder) }); }); - // Run the required server so your queued jobs will get executed - builder.Services.AddHangfireServer(); - + if (!settings.Disabled.GetValueOrDefault(false)) + { + // Run the required server so your queued jobs will get executed + builder.Services.AddHangfireServer(); + } + AddAuthorizedUmbracoDashboard(builder); // For some reason we need to give it the connection string again, else we get this error: // https://discuss.hangfire.io/t/jobstorage-current-property-value-has-not-been-initialized/884 diff --git a/Cultiv.Hangfire/HangfireSettings.cs b/Cultiv.Hangfire/HangfireSettings.cs new file mode 100644 index 0000000..6f1e430 --- /dev/null +++ b/Cultiv.Hangfire/HangfireSettings.cs @@ -0,0 +1,6 @@ +namespace Cultiv.Hangfire; + +public class HangfireSettings +{ + public bool? Disabled { get; set; } +} \ No newline at end of file