Skip to content

Commit

Permalink
Add some metrics on the main dashboard
Browse files Browse the repository at this point in the history
Upgrade Hangfire dependency
Some housekeeping (cleanup refactoring)
  • Loading branch information
nul800sebastiaan committed Nov 9, 2022
1 parent 269a110 commit 202124c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cultiv.Hangfire/Cultiv.Hangfire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.7.30" />
<PackageReference Include="Hangfire" Version="1.7.31" />
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
<PackageReference Include="Umbraco.Cms.Core" Version="10.0.0" />
<PackageReference Include="Umbraco.Cms.Persistence.SqlServer" Version="10.0.0" />
Expand Down
13 changes: 10 additions & 3 deletions Cultiv.Hangfire/HangfireComposer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using Hangfire;
using Hangfire.Console;
using Hangfire.Dashboard;
using Hangfire.SqlServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
Expand All @@ -27,17 +29,22 @@ public void Compose(IUmbracoBuilder builder)

// Explicitly use the SqlConnection in the Microsoft.Data namespace to support extended connection string parameters such as "authentication"
// https://github.com/HangfireIO/Hangfire/issues/1827
var dbConnFunc = () => new Microsoft.Data.SqlClient.SqlConnection(connectionString);
SqlConnection ConnectionFactory() => new(connectionString);

// Configure Hangfire to use our current database and add the option to write console messages
builder.Services.AddHangfire(configuration =>
{
configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseColouredConsoleLogProvider()
.UseDashboardMetric(SqlServerStorage.ActiveConnections)
.UseDashboardMetric(SqlServerStorage.TotalConnections)
.UseDashboardMetric(DashboardMetrics.AwaitingCount)
.UseDashboardMetric(DashboardMetrics.FailedCount)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseConsole()
.UseSqlServerStorage(dbConnFunc, new SqlServerStorageOptions
.UseSqlServerStorage((Func<SqlConnection>)ConnectionFactory, new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
Expand All @@ -54,7 +61,7 @@ public void Compose(IUmbracoBuilder 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
JobStorage.Current = new SqlServerStorage(dbConnFunc);
JobStorage.Current = new SqlServerStorage((Func<SqlConnection>)ConnectionFactory);
}

private static void AddAuthorizedUmbracoDashboard(IUmbracoBuilder builder)
Expand Down
10 changes: 4 additions & 6 deletions Cultiv.Hangfire/wwwroot/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<style type="text/css">
<style>
.hangfireWrapper {
margin: -30px -20px;
}

.hangfireContent {
position: absolute;
width: 100%;
width: 100%!important;
height: 100%;
}
</style>

<div class="hangfireWrapper">
<iframe name="hangfireIframe" class="hangfireContent" id="Hangfire" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0"
src="/umbraco/backoffice/hangfire/" allowfullscreen="true" style="width:100%!important"
webkitallowfullscreen="true" mozallowfullscreen="true"
oallowfullscreen msallowfullscreen="true" onLoad="makeBodyWider();"></iframe>
<iframe name="hangfireIframe" class="hangfireContent" id="Hangfire" src="/umbraco/backoffice/hangfire/"
onLoad="makeBodyWider();"></iframe>
</div>

<script>
Expand Down

0 comments on commit 202124c

Please sign in to comment.