Changes startup logic, no more "Boot" method, the component just handles events

This commit is contained in:
Shannon
2021-05-24 12:51:40 -07:00
parent be3bfe1b63
commit eba3c82a86
3 changed files with 26 additions and 35 deletions

View File

@@ -111,17 +111,11 @@ namespace Umbraco.Core.Sync
#region Sync
/// <summary>
/// Boots the messenger.
/// </summary>
/// <remarks>
/// Thread safety: this is NOT thread safe. Because it is NOT meant to run multi-threaded.
/// Callers MUST ensure thread-safety.
/// </remarks>
[Obsolete("This is no longer used and will be removed in future versions")]
protected void Boot()
{
var bootState = GetSyncBootState();
Booting?.Invoke(this, bootState);
// if called, just forces the boot logic
_ = GetSyncBootState();
}
private SyncBootState BootInternal()
@@ -545,8 +539,6 @@ namespace Umbraco.Core.Sync
+ "/D" + AppDomain.CurrentDomain.Id // eg 22
+ "] " + Guid.NewGuid().ToString("N").ToUpper(); // make it truly unique
public event EventHandler<SyncBootState> Booting;
private string GetDistCacheFilePath(IGlobalSettings globalSettings)
{
var fileName = HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt";
@@ -565,7 +557,7 @@ namespace Umbraco.Core.Sync
#endregion
public SyncBootState GetSyncBootState() => _getSyncBootState.Value;
public virtual SyncBootState GetSyncBootState() => _getSyncBootState.Value;
#region Notify refreshers

View File

@@ -26,6 +26,7 @@ namespace Umbraco.Web
public class BatchedDatabaseServerMessenger : DatabaseServerMessenger
{
private readonly IUmbracoDatabaseFactory _databaseFactory;
private readonly Lazy<SyncBootState> _syncBootState;
[Obsolete("This overload should not be used, enableDistCalls has no effect")]
[EditorBrowsable(EditorBrowsableState.Never)]
@@ -39,28 +40,22 @@ namespace Umbraco.Web
: base(runtime, scopeProvider, sqlContext, proflog, globalSettings, true, options)
{
_databaseFactory = databaseFactory;
}
// invoked by DatabaseServerRegistrarAndMessengerComponent
internal void Startup()
{
UmbracoModule.EndRequest += UmbracoModule_EndRequest;
if (_databaseFactory.CanConnect == false)
_syncBootState = new Lazy<SyncBootState>(() =>
{
Logger.Warn<BatchedDatabaseServerMessenger>("Cannot connect to the database, distributed calls will not be enabled for this server.");
}
else
{
Boot();
}
if (_databaseFactory.CanConnect == false)
{
Logger.Warn<BatchedDatabaseServerMessenger>("Cannot connect to the database, distributed calls will not be enabled for this server.");
return SyncBootState.Unknown;
}
else
{
return base.GetSyncBootState();
}
});
}
private void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs e)
{
// will clear the batch - will remain in HttpContext though - that's ok
FlushBatch();
}
// override to deal with database connectivity
public override SyncBootState GetSyncBootState() => _syncBootState.Value;
protected override void DeliverRemote(ICacheRefresher refresher, MessageType messageType, IEnumerable<object> ids = null, string json = null)
{

View File

@@ -59,15 +59,19 @@ namespace Umbraco.Web.Compose
if (_registrar != null || _messenger != null)
{
UmbracoModule.RouteAttempt += RegisterBackgroundTasksOnce;
}
// must come last, as it references some _variables
_messenger?.Startup();
UmbracoModule.EndRequest += UmbracoModule_EndRequest;
}
}
public void Terminate()
{ }
private void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs e)
{
// will clear the batch - will remain in HttpContext though - that's ok
_messenger?.FlushBatch();
}
/// <summary>
/// Handle when a request is made
/// </summary>