diff --git a/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs b/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs deleted file mode 100644 index 64cd61ad26..0000000000 --- a/src/Umbraco.Core/Configuration/Models/KeepAliveSettings.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.ComponentModel; - -namespace Umbraco.Cms.Core.Configuration.Models; - -/// -/// Typed configuration options for keep alive settings. -/// -[UmbracoOptions(Constants.Configuration.ConfigKeepAlive)] -public class KeepAliveSettings -{ - internal const bool StaticDisableKeepAliveTask = false; - internal const string StaticKeepAlivePingUrl = "~/api/keepalive/ping"; - - /// - /// Gets or sets a value indicating whether the keep alive task is disabled. - /// - [DefaultValue(StaticDisableKeepAliveTask)] - public bool DisableKeepAliveTask { get; set; } = StaticDisableKeepAliveTask; - - /// - /// Gets or sets a value for the keep alive ping URL. - /// - [DefaultValue(StaticKeepAlivePingUrl)] - public string KeepAlivePingUrl { get; set; } = StaticKeepAlivePingUrl; -} diff --git a/src/Umbraco.Core/Constants-Configuration.cs b/src/Umbraco.Core/Constants-Configuration.cs index 6d14f5c7c9..4dfb89fff9 100644 --- a/src/Umbraco.Core/Constants-Configuration.cs +++ b/src/Umbraco.Core/Constants-Configuration.cs @@ -39,7 +39,6 @@ public static partial class Constants public const string ConfigImaging = ConfigPrefix + "Imaging"; public const string ConfigExamine = ConfigPrefix + "Examine"; public const string ConfigIndexing = ConfigPrefix + "Indexing"; - public const string ConfigKeepAlive = ConfigPrefix + "KeepAlive"; public const string ConfigLogging = ConfigPrefix + "Logging"; public const string ConfigMemberPassword = ConfigPrefix + "Security:MemberPassword"; public const string ConfigModelsBuilder = ConfigPrefix + "ModelsBuilder"; diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs index b42aa5a0eb..b80c21b3fe 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs @@ -68,7 +68,6 @@ public static partial class UmbracoBuilderExtensions .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() - .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() diff --git a/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJob.cs b/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJob.cs deleted file mode 100644 index a9849ddbb7..0000000000 --- a/src/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJob.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Routing; -using Umbraco.Cms.Core.Runtime; -using Umbraco.Cms.Core.Sync; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs; - -/// -/// Hosted service implementation for keep alive feature. -/// -public class KeepAliveJob : IRecurringBackgroundJob -{ - public TimeSpan Period { get => TimeSpan.FromMinutes(5); } - - // No-op event as the period never changes on this job - public event EventHandler PeriodChanged { add { } remove { } } - - private readonly IHostingEnvironment _hostingEnvironment; - private readonly IHttpClientFactory _httpClientFactory; - private readonly ILogger _logger; - private readonly IProfilingLogger _profilingLogger; - private KeepAliveSettings _keepAliveSettings; - - /// - /// Initializes a new instance of the class. - /// - /// The current hosting environment - /// The configuration for keep alive settings. - /// The typed logger. - /// The profiling logger. - /// Factory for instances. - public KeepAliveJob( - IHostingEnvironment hostingEnvironment, - IOptionsMonitor keepAliveSettings, - ILogger logger, - IProfilingLogger profilingLogger, - IHttpClientFactory httpClientFactory) - { - _hostingEnvironment = hostingEnvironment; - _keepAliveSettings = keepAliveSettings.CurrentValue; - _logger = logger; - _profilingLogger = profilingLogger; - _httpClientFactory = httpClientFactory; - - keepAliveSettings.OnChange(x => _keepAliveSettings = x); - } - - public async Task RunJobAsync() - { - if (_keepAliveSettings.DisableKeepAliveTask) - { - return; - } - - using (_profilingLogger.DebugDuration("Keep alive executing", "Keep alive complete")) - { - var umbracoAppUrl = _hostingEnvironment.ApplicationMainUrl?.ToString(); - if (umbracoAppUrl.IsNullOrWhiteSpace()) - { - _logger.LogWarning("No umbracoApplicationUrl for service (yet), skip."); - return; - } - - // If the config is an absolute path, just use it - var keepAlivePingUrl = WebPath.Combine( - umbracoAppUrl!, - _hostingEnvironment.ToAbsolute(_keepAliveSettings.KeepAlivePingUrl)); - - try - { - var request = new HttpRequestMessage(HttpMethod.Get, keepAlivePingUrl); - HttpClient httpClient = _httpClientFactory.CreateClient(Constants.HttpClients.IgnoreCertificateErrors); - _ = await httpClient.SendAsync(request); - } - catch (Exception ex) - { - _logger.LogError(ex, "Keep alive failed (at '{keepAlivePingUrl}').", keepAlivePingUrl); - } - } - } -} diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index 77935ee95d..668e3c79ca 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -176,7 +176,6 @@ public static partial class UmbracoBuilderExtensions { // Add background jobs builder.Services.AddRecurringBackgroundJob(); - builder.Services.AddRecurringBackgroundJob(); builder.Services.AddRecurringBackgroundJob(); builder.Services.AddRecurringBackgroundJob(); builder.Services.AddRecurringBackgroundJob(); diff --git a/src/Umbraco.Web.UI/appsettings.template.json b/src/Umbraco.Web.UI/appsettings.template.json index b7aa07acf8..698eb83955 100644 --- a/src/Umbraco.Web.UI/appsettings.template.json +++ b/src/Umbraco.Web.UI/appsettings.template.json @@ -30,10 +30,6 @@ "Hosting": { "Debug": false }, - "KeepAlive": { - "DisableKeepAliveTask": false, - "KeepAlivePingUrl": "~/api/keepalive/ping" - }, "RequestHandler": { "ConvertUrlsToAscii": "try" }, diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJobTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJobTests.cs deleted file mode 100644 index 6821cbcccc..0000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackgroundJobs/Jobs/KeepAliveJobTests.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Net; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Moq; -using Moq.Protected; -using NUnit.Framework; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Runtime; -using Umbraco.Cms.Core.Scoping; -using Umbraco.Cms.Core.Sync; -using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs; -using Umbraco.Cms.Infrastructure.HostedServices; -using Umbraco.Cms.Tests.Common; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.BackgroundJobs.Jobs; - -[TestFixture] -public class KeepAliveJobTests -{ - private Mock _mockHttpMessageHandler; - - private const string ApplicationUrl = "https://mysite.com"; - - [Test] - public async Task Does_Not_Execute_When_Not_Enabled() - { - var sut = CreateKeepAlive(false); - await sut.RunJobAsync(); - VerifyKeepAliveRequestNotSent(); - } - - - [Test] - public async Task Executes_And_Calls_Ping_Url() - { - var sut = CreateKeepAlive(); - await sut.RunJobAsync(); - VerifyKeepAliveRequestSent(); - } - - private KeepAliveJob CreateKeepAlive( - bool enabled = true) - { - var settings = new KeepAliveSettings { DisableKeepAliveTask = !enabled }; - - var mockHostingEnvironment = new Mock(); - mockHostingEnvironment.SetupGet(x => x.ApplicationMainUrl).Returns(new Uri(ApplicationUrl)); - mockHostingEnvironment.Setup(x => x.ToAbsolute(It.IsAny())) - .Returns((string s) => s.TrimStart('~')); - - var mockScopeProvider = new Mock(); - var mockLogger = new Mock>(); - var mockProfilingLogger = new Mock(); - - _mockHttpMessageHandler = new Mock(); - _mockHttpMessageHandler.Protected() - .Setup>( - "SendAsync", - ItExpr.IsAny(), - ItExpr.IsAny()) - .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)) - .Verifiable(); - _mockHttpMessageHandler.As().Setup(s => s.Dispose()); - var httpClient = new HttpClient(_mockHttpMessageHandler.Object); - - var mockHttpClientFactory = new Mock(MockBehavior.Strict); - mockHttpClientFactory.Setup(x => x.CreateClient(It.IsAny())).Returns(httpClient); - - return new KeepAliveJob( - mockHostingEnvironment.Object, - new TestOptionsMonitor(settings), - mockLogger.Object, - mockProfilingLogger.Object, - mockHttpClientFactory.Object); - } - - private void VerifyKeepAliveRequestNotSent() => VerifyKeepAliveRequestSentTimes(Times.Never()); - - private void VerifyKeepAliveRequestSent() => VerifyKeepAliveRequestSentTimes(Times.Once()); - - private void VerifyKeepAliveRequestSentTimes(Times times) => _mockHttpMessageHandler.Protected() - .Verify( - "SendAsync", - times, - ItExpr.Is(x => x.RequestUri.ToString() == $"{ApplicationUrl}/api/keepalive/ping"), - ItExpr.IsAny()); -} diff --git a/tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs b/tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs index a289a45ec3..f708644634 100644 --- a/tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs +++ b/tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs @@ -39,8 +39,6 @@ internal class UmbracoCmsSchema public IndexCreatorSettings Examine { get; set; } = null!; public IndexingSettings Indexing { get; set; } = null!; - public KeepAliveSettings KeepAlive { get; set; } = null!; - public LoggingSettings Logging { get; set; } = null!; public NuCacheSettings NuCache { get; set; } = null!;