Skip to content

Commit

Permalink
Merge pull request #10 from meyntony/main
Browse files Browse the repository at this point in the history
Add `hangfireDB` as an alternative to `umbracoDbDSN` and fix null ref error on Cloud
  • Loading branch information
nul800sebastiaan authored Jul 19, 2022
2 parents 6f16ad9 + 1130d16 commit 2f86222
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cultiv.Hangfire/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static class System
{
public const string HangfireDashboard = nameof(HangfireDashboard);
public const string Endpoint = "/umbraco/backoffice/hangfire";
public const string AlternativeConnectionStringName = "hangfireDB";
}
}
}
26 changes: 19 additions & 7 deletions Cultiv.Hangfire/HangfireComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public class HangfireComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var providerName = builder.Config.GetConnectionStringProviderName(Umbraco.Cms.Core.Constants.System.UmbracoConnectionName);
if (providerName != Umbraco.Cms.Persistence.SqlServer.Constants.ProviderName)
{
throw new NotSupportedException($"Cultiv.Hangfire only works on SQL Server and LocalDb, your current provider ({providerName}) is not supported.");
}
var connectionString = GetConnectionString(builder);

var connectionString = builder.Config.GetUmbracoConnectionString();
// Configure Hangfire to use our current database and add the option to write console messages
builder.Services.AddHangfire(configuration =>
{
Expand Down Expand Up @@ -68,5 +63,22 @@ private static void AddAuthorizedUmbracoDashboard(IUmbracoBuilder builder)
});
});
}

private static string GetConnectionString(IUmbracoBuilder builder)
{
var connectionString = builder.Config.GetUmbracoConnectionString(Constants.System.AlternativeConnectionStringName);
if (string.IsNullOrWhiteSpace(connectionString) == false)
{
return connectionString;
}

var providerName = builder.Config.GetConnectionStringProviderName(Umbraco.Cms.Core.Constants.System.UmbracoConnectionName);
if (providerName != null && providerName != Umbraco.Cms.Persistence.SqlServer.Constants.ProviderName)
{
throw new NotSupportedException($"Cultiv.Hangfire only works on SQL Server and LocalDb, your current provider ({providerName}) is not supported.");
}

return builder.Config.GetUmbracoConnectionString();
}
}
}
}

0 comments on commit 2f86222

Please sign in to comment.