Skip to content

Commit

Permalink
Fixes #18 Add option to disable Hangfire server
Browse files Browse the repository at this point in the history
  • Loading branch information
nul800sebastiaan committed Sep 18, 2023
1 parent 98caa8e commit 622d88f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
29 changes: 19 additions & 10 deletions Cultiv.Hangfire/HangfireComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,9 +18,11 @@ namespace Cultiv.Hangfire;

public class HangfireComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.ManifestFilters().Append<ManifestFilter>();
public void Compose(IUmbracoBuilder builder)
{
var settings = builder.Config.GetSection("Hangfire:Server").Get<HangfireSettings>();

builder.ManifestFilters().Append<ManifestFilter>();

var provider = builder.Config.GetConnectionStringProviderName(Umbraco.Cms.Core.Constants.System.UmbracoConnectionName);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Cultiv.Hangfire/HangfireSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Cultiv.Hangfire;

public class HangfireSettings
{
public bool? Disabled { get; set; }
}

0 comments on commit 622d88f

Please sign in to comment.