mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-20 10:06:07 +08:00
Retrying on tenant startup
Conflicts: src/Orchard.Web/Config/HostComponents.config src/Orchard/Environment/DefaultOrchardHost.cs
This commit is contained in:
parent
aae9f6270e
commit
712ff2f487
@ -106,5 +106,14 @@
|
||||
</Properties>
|
||||
</Component>
|
||||
|
||||
<Component Type="Orchard.Environment.DefaultOrchardHost">
|
||||
<Properties>
|
||||
<!-- The number of retries when a tenant can't be loaded -->
|
||||
<Property Name="Retries" Value="1"/>
|
||||
<Property Name="DelayRetries" Value="true"/>
|
||||
|
||||
</Properties>
|
||||
</Component>
|
||||
|
||||
</Components>
|
||||
</HostComponents>
|
||||
|
||||
@ -14,6 +14,7 @@ using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Exceptions;
|
||||
using System.Threading;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
// All the event handlers that DefaultOrchardHost implements have to be declared in OrchardStarter
|
||||
@ -32,6 +33,10 @@ namespace Orchard.Environment {
|
||||
private IEnumerable<ShellContext> _shellContexts;
|
||||
|
||||
private readonly ContextState<IList<ShellSettings>> _tenantsToRestart;
|
||||
public int Retries { get; set; }
|
||||
|
||||
public bool DelayRetries { get; set; }
|
||||
|
||||
public DefaultOrchardHost(
|
||||
IShellSettingsManager shellSettingsManager,
|
||||
IShellContextFactory shellContextFactory,
|
||||
@ -137,16 +142,32 @@ namespace Orchard.Environment {
|
||||
// load all tenants, and activate their shell
|
||||
if (allSettings.Any()) {
|
||||
Parallel.ForEach(allSettings, settings => {
|
||||
try {
|
||||
var context = CreateShellContext(settings);
|
||||
ActivateShell(context);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex.IsFatal()) {
|
||||
throw;
|
||||
}
|
||||
Logger.Error(ex, "A tenant could not be started: " + settings.Name);
|
||||
for (var i = 0; i <= Retries; i++) {
|
||||
|
||||
// Not the first attempt, wait for a while ...
|
||||
if (DelayRetries && i > 0) {
|
||||
// Waits for i^2 which means 1, 2, 4, 8 ... seconds
|
||||
Thread.Sleep(TimeSpan.FromSeconds(Math.Pow(i, 2)));
|
||||
}
|
||||
|
||||
bool failed = false;
|
||||
try {
|
||||
var context = CreateShellContext(settings);
|
||||
ActivateShell(context);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// An exception at this point is always fatal as it literally kills the
|
||||
// tenant. What is more fatal than something that kills you?
|
||||
Logger.Error(ex, "A tenant could not be started: " + settings.Name + " Attempt number: " + i);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
if(failed && i == Retries) {
|
||||
Logger.Fatal("A tenant could not be started: {0} after {1} retries.", settings.Name, Retries);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (_processingEngine.AreTasksPending()) {
|
||||
Logger.Debug("Processing pending task after activate Shell");
|
||||
_processingEngine.ExecuteNextTask();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user