Stop TouchServerTask is registered role accessor is not elected
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
/// </summary>
|
||||
protected static readonly TimeSpan DefaultDelay = TimeSpan.FromMinutes(3);
|
||||
|
||||
private readonly TimeSpan _period;
|
||||
private TimeSpan _period;
|
||||
private readonly TimeSpan _delay;
|
||||
private Timer _timer;
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
|
||||
/// <inheritdoc/>
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_period = Timeout.InfiniteTimeSpan;
|
||||
_timer?.Change(Timeout.Infinite, 0);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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.Services;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Web.Common.DependencyInjection;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration
|
||||
@@ -22,6 +26,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration
|
||||
private readonly IServerRegistrationService _serverRegistrationService;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ILogger<TouchServerTask> _logger;
|
||||
private readonly IServerRoleAccessor _serverRoleAccessor;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
|
||||
/// <summary>
|
||||
@@ -37,7 +42,8 @@ namespace Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration
|
||||
IServerRegistrationService serverRegistrationService,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
ILogger<TouchServerTask> logger,
|
||||
IOptions<GlobalSettings> globalSettings)
|
||||
IOptions<GlobalSettings> globalSettings,
|
||||
IServerRoleAccessor serverRoleAccessor)
|
||||
: base(globalSettings.Value.DatabaseServerRegistrar.WaitTimeBetweenCalls, TimeSpan.FromSeconds(15))
|
||||
{
|
||||
_runtimeState = runtimeState;
|
||||
@@ -45,6 +51,24 @@ namespace Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings.Value;
|
||||
_serverRoleAccessor = serverRoleAccessor;
|
||||
}
|
||||
|
||||
[Obsolete("Use constructor that takes an IServerRoleAccessor")]
|
||||
public TouchServerTask(
|
||||
IRuntimeState runtimeState,
|
||||
IServerRegistrationService serverRegistrationService,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
ILogger<TouchServerTask> logger,
|
||||
IOptions<GlobalSettings> globalSettings)
|
||||
: this(
|
||||
runtimeState,
|
||||
serverRegistrationService,
|
||||
hostingEnvironment,
|
||||
logger,
|
||||
globalSettings,
|
||||
StaticServiceProvider.Instance.GetRequiredService<IServerRoleAccessor>())
|
||||
{
|
||||
}
|
||||
|
||||
public override Task PerformExecuteAsync(object state)
|
||||
@@ -54,6 +78,14 @@ namespace Umbraco.Cms.Infrastructure.HostedServices.ServerRegistration
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// If we're the IServerRoleAccessor has been changed away from ElectedServerRoleAccessor
|
||||
// this task no longer makes sense, since all it's used for is to allow the ElectedServerRoleAccessor
|
||||
// to figure out what role a given server has, so we just stop this task.
|
||||
if (_serverRoleAccessor is not ElectedServerRoleAccessor)
|
||||
{
|
||||
return StopAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
var serverAddress = _hostingEnvironment.ApplicationMainUrl?.ToString();
|
||||
if (serverAddress.IsNullOrWhiteSpace())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user