Load Balancing: Implement distributed background jobs (#20397)
* Start work * Introduce dto * Start making repository * Add migrations * Implement fetchable first job * Fix up to also finish tasks * Refactor jobs to distributed background jobs * Filter jobs correctly on LastRun * Hardcode delay * Add settings to configure delay and period * Fix formatting * Add default data * Add update on startup, which will update periods on startup * Refactor service to return job directly * Update src/Umbraco.Infrastructure/Services/Implement/DistributedJobService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove unused * Move jobs and make internal * make OpenIddictCleanupJob.cs public, as it is used elsewhere * Minor docstring changes * Update src/Umbraco.Core/Persistence/Constants-Locks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * ´Throw correct exceptions * Update xml doc * Remove business logic from repository * Remove more business logic from repository into service * Remove adding jobs from migration * fix creation * Rename to ExecuteAsync --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
@@ -9,6 +9,7 @@ using Umbraco.Cms.Core.Runtime;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
||||
using Umbraco.Cms.Infrastructure.HostedServices;
|
||||
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
||||
|
||||
@@ -35,7 +36,7 @@ internal class ContentVersionCleanupTest
|
||||
mainDom.Setup(x => x.IsMainDom).Returns(true);
|
||||
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
|
||||
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
|
||||
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Never);
|
||||
}
|
||||
@@ -59,7 +60,7 @@ internal class ContentVersionCleanupTest
|
||||
mainDom.Setup(x => x.IsMainDom).Returns(true);
|
||||
serverRoleAccessor.Setup(x => x.CurrentServerRole).Returns(ServerRole.SchedulingPublisher);
|
||||
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
|
||||
cleanupService.Verify(x => x.PerformContentVersionCleanup(It.IsAny<DateTime>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.BackgroundJobs.Jobs;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class CacheInstructionsPruningJobTests
|
||||
|
||||
var job = CreateCacheInstructionsPruningJob(timeToRetainInstructions: timeToRetainInstructions);
|
||||
|
||||
await job.RunJobAsync();
|
||||
await job.ExecuteAsync();
|
||||
|
||||
_cacheInstructionRepositoryMock.Verify(repo => repo.DeleteInstructionsOlderThan(expectedPruneDate), Times.Once);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.HealthChecks;
|
||||
using Umbraco.Cms.Core.HealthChecks.NotificationMethods;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Runtime;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
||||
using Umbraco.Cms.Infrastructure.Scoping;
|
||||
using Umbraco.Cms.Tests.Common;
|
||||
|
||||
@@ -37,7 +29,7 @@ public class HealthCheckNotifierJobTests
|
||||
public async Task Does_Not_Execute_When_Not_Enabled()
|
||||
{
|
||||
var sut = CreateHealthCheckNotifier(false);
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyNotificationsNotSent();
|
||||
}
|
||||
|
||||
@@ -45,7 +37,7 @@ public class HealthCheckNotifierJobTests
|
||||
public async Task Does_Not_Execute_With_No_Enabled_Notification_Methods()
|
||||
{
|
||||
var sut = CreateHealthCheckNotifier(notificationEnabled: false);
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyNotificationsNotSent();
|
||||
}
|
||||
|
||||
@@ -53,7 +45,7 @@ public class HealthCheckNotifierJobTests
|
||||
public async Task Executes_With_Enabled_Notification_Methods()
|
||||
{
|
||||
var sut = CreateHealthCheckNotifier();
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyNotificationsSent();
|
||||
}
|
||||
|
||||
@@ -61,7 +53,7 @@ public class HealthCheckNotifierJobTests
|
||||
public async Task Executes_Only_Enabled_Checks()
|
||||
{
|
||||
var sut = CreateHealthCheckNotifier();
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
_mockNotificationMethod.Verify(
|
||||
x => x.SendAsync(
|
||||
It.Is<HealthCheckResults>(y =>
|
||||
@@ -96,7 +88,6 @@ public class HealthCheckNotifierJobTests
|
||||
|
||||
|
||||
var mockScopeProvider = new Mock<IScopeProvider>();
|
||||
var mockLogger = new Mock<ILogger<HealthCheckNotifierJob>>();
|
||||
var mockProfilingLogger = new Mock<IProfilingLogger>();
|
||||
|
||||
return new HealthCheckNotifierJob(
|
||||
@@ -104,9 +95,7 @@ public class HealthCheckNotifierJobTests
|
||||
checks,
|
||||
notifications,
|
||||
mockScopeProvider.Object,
|
||||
mockLogger.Object,
|
||||
mockProfilingLogger.Object,
|
||||
Mock.Of<ICronTabParser>(),
|
||||
Mock.Of<IEventAggregator>());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,15 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Runtime;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
||||
using Umbraco.Cms.Infrastructure.HostedServices;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
||||
using Umbraco.Cms.Tests.Common;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.BackgroundJobs.Jobs;
|
||||
@@ -30,7 +26,7 @@ public class LogScrubberJobTests
|
||||
public async Task Executes_And_Scrubs_Logs()
|
||||
{
|
||||
var sut = CreateLogScrubber();
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyLogsScrubbed();
|
||||
}
|
||||
|
||||
@@ -50,7 +46,6 @@ public class LogScrubberJobTests
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()))
|
||||
.Returns(mockScope.Object);
|
||||
var mockLogger = new Mock<ILogger<LogScrubberJob>>();
|
||||
var mockProfilingLogger = new Mock<IProfilingLogger>();
|
||||
|
||||
_mockAuditService = new Mock<IAuditService>();
|
||||
@@ -59,7 +54,6 @@ public class LogScrubberJobTests
|
||||
_mockAuditService.Object,
|
||||
new TestOptionsMonitor<LoggingSettings>(settings),
|
||||
mockScopeProvider.Object,
|
||||
mockLogger.Object,
|
||||
mockProfilingLogger.Object);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Core.Web;
|
||||
using Umbraco.Cms.Infrastructure;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs;
|
||||
using Umbraco.Cms.Infrastructure.BackgroundJobs.Jobs.DistributedJobs;
|
||||
using Umbraco.Cms.Infrastructure.HostedServices;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.BackgroundJobs.Jobs;
|
||||
@@ -29,7 +30,7 @@ public class ScheduledPublishingJobTests
|
||||
public async Task Does_Not_Execute_When_Not_Enabled()
|
||||
{
|
||||
var sut = CreateScheduledPublishing(enabled: false);
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyScheduledPublishingNotPerformed();
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ public class ScheduledPublishingJobTests
|
||||
public async Task Executes_And_Performs_Scheduled_Publishing()
|
||||
{
|
||||
var sut = CreateScheduledPublishing();
|
||||
await sut.RunJobAsync();
|
||||
await sut.ExecuteAsync();
|
||||
VerifyScheduledPublishingPerformed();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user