From fa2efcb26ebf97876a63edcca2c9774114ac148b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Kottal?= Date: Mon, 7 Oct 2024 12:04:17 +0200 Subject: [PATCH] Makes SqlServerStorage configurable --- Cultiv.Hangfire/HangfireComposer.cs | 18 +++++++++--------- Cultiv.Hangfire/HangfireSettings.cs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Cultiv.Hangfire/HangfireComposer.cs b/Cultiv.Hangfire/HangfireComposer.cs index 45a6f4e..ec64bad 100644 --- a/Cultiv.Hangfire/HangfireComposer.cs +++ b/Cultiv.Hangfire/HangfireComposer.cs @@ -1,5 +1,4 @@ -using System; -using Hangfire; +using Hangfire; using Hangfire.Console; using Hangfire.Dashboard; using Hangfire.SqlServer; @@ -8,6 +7,7 @@ using Microsoft.Data.SqlClient; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using System; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Web.Common.ApplicationBuilder; @@ -87,13 +87,13 @@ public void Compose(IUmbracoBuilder builder) .UseConsole() .UseSqlServerStorage((Func)ConnectionFactory, new SqlServerStorageOptions { - PrepareSchemaIfNecessary = true, - EnableHeavyMigrations = true, - CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), - SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), - QueuePollInterval = TimeSpan.Zero, - UseRecommendedIsolationLevel = true, - DisableGlobalLocks = true + PrepareSchemaIfNecessary = settings.StorageOptions.PrepareSchemaIfNecessary, + EnableHeavyMigrations = settings.StorageOptions.EnableHeavyMigrations, + CommandBatchMaxTimeout = settings.StorageOptions.CommandBatchMaxTimeout, + SlidingInvisibilityTimeout = settings.StorageOptions.SlidingInvisibilityTimeout, + QueuePollInterval = settings.StorageOptions.QueuePollInterval, + UseRecommendedIsolationLevel = settings.StorageOptions.UseRecommendedIsolationLevel, + DisableGlobalLocks = settings.StorageOptions.DisableGlobalLocks }); }); diff --git a/Cultiv.Hangfire/HangfireSettings.cs b/Cultiv.Hangfire/HangfireSettings.cs index 0cb504d..5a75340 100644 --- a/Cultiv.Hangfire/HangfireSettings.cs +++ b/Cultiv.Hangfire/HangfireSettings.cs @@ -1,11 +1,25 @@ -namespace Cultiv.Hangfire; +using System; + +namespace Cultiv.Hangfire; public class HangfireSettings { public Server Server { get; set; } + public StorageOptions StorageOptions { get; set; } = new StorageOptions(); } public class Server { - public bool? Disabled { get; set; } + public bool? Disabled { get; set; } +} + +public class StorageOptions +{ + public bool PrepareSchemaIfNecessary { get; set; } = true; + public bool EnableHeavyMigrations { get; set; } = true; + public TimeSpan CommandBatchMaxTimeout { get; set; } = TimeSpan.FromMinutes(5); + public TimeSpan SlidingInvisibilityTimeout { get; set; } = TimeSpan.FromMinutes(5); + public TimeSpan QueuePollInterval { get; set; } = TimeSpan.Zero; + public bool UseRecommendedIsolationLevel { get; set; } = true; + public bool DisableGlobalLocks { get; set; } = true; } \ No newline at end of file