Added "service unavailable" support for the currently requested shell.

This commit is contained in:
Sipke Schoorstra
2015-09-10 23:18:43 +01:00
parent 256b1313b2
commit 9897f6ada5
3 changed files with 12 additions and 7 deletions

View File

@@ -382,7 +382,7 @@ namespace Orchard.Data.Migration.Interpreters {
} }
} }
finally { finally {
_sqlStatements.Clear(); _sqlStatements.Clear();
} }
} }

View File

@@ -12,6 +12,7 @@ using Orchard.Environment.Descriptor.Models;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Mvc; using Orchard.Mvc;
using Orchard.Mvc.Extensions;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
namespace Orchard.Environment { namespace Orchard.Environment {
@@ -348,13 +349,18 @@ namespace Orchard.Environment {
} }
private void BlockRequestsDuringSetup() { private void BlockRequestsDuringSetup() {
if (_shellContexts == null) var httpContext = _httpContextAccessor.Current();
if (httpContext.IsBackgroundContext())
return; return;
// If there's only one tenant and it's initializing, return a Service Unavailable HTTP status code. // Get the requested shell.
var shellContexts = _shellContexts.ToList(); var runningShell = _runningShellTable.Match(httpContext);
if (shellContexts.Count == 1 && shellContexts[0].Settings.State == TenantState.Initializing) { if (runningShell == null)
var response = _httpContextAccessor.Current().Response; return;
// If the requested shell is currently initializing, return a Service Unavailable HTTP status code.
if (runningShell.State == TenantState.Initializing) {
var response = httpContext.Response;
response.StatusCode = 503; response.StatusCode = 503;
response.StatusDescription = "Orchard is currently setting up. Please check back in a few moments."; 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."); response.Write("Orchard is currently setting up. Please check back in a few moments.");

View File

@@ -94,7 +94,6 @@ namespace Orchard.Environment {
SafelyTerminate(() => _sweepGenerator.Terminate()); SafelyTerminate(() => _sweepGenerator.Terminate());
} }
private void SafelyTerminate(Action action) { private void SafelyTerminate(Action action) {
try { try {
action(); action();