mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Changed the handling of the Initializing shell status.
This improves the responsiveness of subsequent requests coming in dramatically.
This commit is contained in:
@@ -44,12 +44,9 @@ namespace Orchard.Setup.Controllers {
|
|||||||
|
|
||||||
public ActionResult Index() {
|
public ActionResult Index() {
|
||||||
var initialSettings = _setupService.Prime();
|
var initialSettings = _setupService.Prime();
|
||||||
|
|
||||||
if(initialSettings.State == TenantState.Initializing)
|
|
||||||
return View("Initializing");
|
|
||||||
|
|
||||||
var recipes = _setupService.Recipes().ToList();
|
var recipes = _setupService.Recipes().ToList();
|
||||||
string recipeDescription = null;
|
string recipeDescription = null;
|
||||||
|
|
||||||
if (recipes.Count > 0) {
|
if (recipes.Count > 0) {
|
||||||
recipeDescription = recipes[0].Description;
|
recipeDescription = recipes[0].Description;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,9 +137,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Document.cshtml" />
|
<Content Include="Views\Document.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="Views\Setup\Initializing.cshtml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ namespace Orchard.Setup.Services {
|
|||||||
|
|
||||||
context.EnabledFeatures = hardcoded.Union(context.EnabledFeatures ?? Enumerable.Empty<string>()).Distinct().ToList();
|
context.EnabledFeatures = hardcoded.Union(context.EnabledFeatures ?? Enumerable.Empty<string>()).Distinct().ToList();
|
||||||
|
|
||||||
|
// Set shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
||||||
|
_shellSettings.State = TenantState.Initializing;
|
||||||
|
|
||||||
var shellSettings = new ShellSettings(_shellSettings);
|
var shellSettings = new ShellSettings(_shellSettings);
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(shellSettings.DataProvider)) {
|
if (String.IsNullOrEmpty(shellSettings.DataProvider)) {
|
||||||
@@ -174,7 +177,7 @@ namespace Orchard.Setup.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
// Reset shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
||||||
shellSettings.State = _shellSettings.State = TenantState.Initializing;
|
shellSettings.State = _shellSettings.State = TenantState.Initializing;
|
||||||
_shellSettingsManager.SaveSettings(shellSettings);
|
_shellSettingsManager.SaveSettings(shellSettings);
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
@T("Orchard is initializing. Please check back in a few minutes.")
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
@@ -12,6 +11,7 @@ using Orchard.Environment.Descriptor;
|
|||||||
using Orchard.Environment.Descriptor.Models;
|
using Orchard.Environment.Descriptor.Models;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
|
using Orchard.Mvc;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Environment {
|
namespace Orchard.Environment {
|
||||||
@@ -25,12 +25,13 @@ namespace Orchard.Environment {
|
|||||||
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
|
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
|
||||||
private readonly IExtensionMonitoringCoordinator _extensionMonitoringCoordinator;
|
private readonly IExtensionMonitoringCoordinator _extensionMonitoringCoordinator;
|
||||||
private readonly ICacheManager _cacheManager;
|
private readonly ICacheManager _cacheManager;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly static object _syncLock = new object();
|
private readonly static object _syncLock = new object();
|
||||||
private readonly static object _shellContextsWriteLock = new object();
|
private readonly static object _shellContextsWriteLock = new object();
|
||||||
|
|
||||||
private IEnumerable<ShellContext> _shellContexts;
|
private IEnumerable<ShellContext> _shellContexts;
|
||||||
|
|
||||||
private readonly ContextState<IList<ShellSettings>> _tenantsToRestart;
|
private readonly ContextState<IList<ShellSettings>> _tenantsToRestart;
|
||||||
|
|
||||||
public DefaultOrchardHost(
|
public DefaultOrchardHost(
|
||||||
IShellSettingsManager shellSettingsManager,
|
IShellSettingsManager shellSettingsManager,
|
||||||
IShellContextFactory shellContextFactory,
|
IShellContextFactory shellContextFactory,
|
||||||
@@ -39,7 +40,9 @@ namespace Orchard.Environment {
|
|||||||
IExtensionLoaderCoordinator extensionLoaderCoordinator,
|
IExtensionLoaderCoordinator extensionLoaderCoordinator,
|
||||||
IExtensionMonitoringCoordinator extensionMonitoringCoordinator,
|
IExtensionMonitoringCoordinator extensionMonitoringCoordinator,
|
||||||
ICacheManager cacheManager,
|
ICacheManager cacheManager,
|
||||||
IHostLocalRestart hostLocalRestart) {
|
IHostLocalRestart hostLocalRestart,
|
||||||
|
IHttpContextAccessor httpContextAccessor) {
|
||||||
|
|
||||||
_shellSettingsManager = shellSettingsManager;
|
_shellSettingsManager = shellSettingsManager;
|
||||||
_shellContextFactory = shellContextFactory;
|
_shellContextFactory = shellContextFactory;
|
||||||
_runningShellTable = runningShellTable;
|
_runningShellTable = runningShellTable;
|
||||||
@@ -48,6 +51,7 @@ namespace Orchard.Environment {
|
|||||||
_extensionMonitoringCoordinator = extensionMonitoringCoordinator;
|
_extensionMonitoringCoordinator = extensionMonitoringCoordinator;
|
||||||
_cacheManager = cacheManager;
|
_cacheManager = cacheManager;
|
||||||
_hostLocalRestart = hostLocalRestart;
|
_hostLocalRestart = hostLocalRestart;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
||||||
_tenantsToRestart = new ContextState<IList<ShellSettings>>("DefaultOrchardHost.TenantsToRestart", () => new List<ShellSettings>());
|
_tenantsToRestart = new ContextState<IList<ShellSettings>>("DefaultOrchardHost.TenantsToRestart", () => new List<ShellSettings>());
|
||||||
|
|
||||||
@@ -189,7 +193,6 @@ namespace Orchard.Environment {
|
|||||||
private ShellContext CreateShellContext(ShellSettings settings) {
|
private ShellContext CreateShellContext(ShellSettings settings) {
|
||||||
switch (settings.State) {
|
switch (settings.State) {
|
||||||
case TenantState.Uninitialized:
|
case TenantState.Uninitialized:
|
||||||
case TenantState.Initializing:
|
|
||||||
Logger.Debug("Creating shell context for tenant {0} setup.", settings.Name);
|
Logger.Debug("Creating shell context for tenant {0} setup.", settings.Name);
|
||||||
return _shellContextFactory.CreateSetupContext(settings);
|
return _shellContextFactory.CreateSetupContext(settings);
|
||||||
default:
|
default:
|
||||||
@@ -236,6 +239,8 @@ namespace Orchard.Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void BeginRequest() {
|
protected virtual void BeginRequest() {
|
||||||
|
BlockRequestsDuringSetup();
|
||||||
|
|
||||||
// Ensure all shell contexts are loaded, or need to be reloaded if
|
// Ensure all shell contexts are loaded, or need to be reloaded if
|
||||||
// extensions have changed
|
// extensions have changed
|
||||||
MonitorExtensions();
|
MonitorExtensions();
|
||||||
@@ -343,6 +348,20 @@ namespace Orchard.Environment {
|
|||||||
_tenantsToRestart.GetState().Add(context.Settings);
|
_tenantsToRestart.GetState().Add(context.Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BlockRequestsDuringSetup() {
|
||||||
|
if (_shellContexts == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If there's only one tenant and it's initializing, return a Service Unavailable HTTP status code.
|
||||||
|
var shellContexts = _shellContexts.ToList();
|
||||||
|
if (shellContexts.Count == 1 && shellContexts[0].Settings.State == TenantState.Initializing) {
|
||||||
|
var response = _httpContextAccessor.Current().Response;
|
||||||
|
response.StatusCode = 503;
|
||||||
|
response.StatusDescription = "Orchard is currently setting up. Please check back in a few moments.";
|
||||||
|
response.Write("Orchard is currently setting up. Please check back in a few moments.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// To be used from CreateStandaloneEnvironment(), also disposes the ShellContext LifetimeScope.
|
// To be used from CreateStandaloneEnvironment(), also disposes the ShellContext LifetimeScope.
|
||||||
private class StandaloneEnvironmentWorkContextScopeWrapper : IWorkContextScope {
|
private class StandaloneEnvironmentWorkContextScopeWrapper : IWorkContextScope {
|
||||||
private readonly ShellContext _shellContext;
|
private readonly ShellContext _shellContext;
|
||||||
|
|||||||
Reference in New Issue
Block a user