mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implementing retry logic in command host
--HG-- branch : dev
This commit is contained in:
@@ -42,14 +42,19 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
public int StartHost(TextReader input, TextWriter output) {
|
||||
try {
|
||||
_hostContainer = OrchardStarter.CreateHostContainer(ContainerRegistrations);
|
||||
_tenants = new Dictionary<string, IStandaloneEnvironment>();
|
||||
|
||||
var host = _hostContainer.Resolve<IOrchardHost>();
|
||||
host.Initialize();
|
||||
// This retry logic is not exactly clean, but a change in configuration
|
||||
// sometimes need us to re-try initializing a host container.
|
||||
Retry:
|
||||
try {
|
||||
_hostContainer = CreateHostContainer();
|
||||
_tenants = new Dictionary<string, IStandaloneEnvironment>();
|
||||
return 0;
|
||||
}
|
||||
catch (OrchardCommandHostRetryException e) {
|
||||
output.WriteLine("{0} (Retrying...)", e.Message);
|
||||
goto Retry;
|
||||
}
|
||||
catch (Exception e) {
|
||||
for (; e != null; e = e.InnerException) {
|
||||
output.WriteLine("Error: {0}", e.Message);
|
||||
@@ -59,6 +64,14 @@ namespace Orchard.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
private IContainer CreateHostContainer() {
|
||||
var hostContainer = OrchardStarter.CreateHostContainer(ContainerRegistrations);
|
||||
|
||||
var host = hostContainer.Resolve<IOrchardHost>();
|
||||
host.Initialize();
|
||||
return hostContainer;
|
||||
}
|
||||
|
||||
|
||||
public int StopHost(TextReader input, TextWriter output) {
|
||||
try {
|
||||
@@ -133,7 +146,7 @@ namespace Orchard.Commands {
|
||||
}
|
||||
else {
|
||||
// In case of an unitiliazed site (no default settings yet), we create a default settings instance.
|
||||
var settings = new ShellSettings {Name = "Default", State = new TenantState("Uninitialized")};
|
||||
var settings = new ShellSettings { Name = "Default", State = new TenantState("Uninitialized") };
|
||||
return host.CreateStandaloneEnvironment(settings);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Web.Hosting;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Commands {
|
||||
public class OrchardCommandHostRetryException : OrchardCoreException {
|
||||
public OrchardCommandHostRetryException(LocalizedString message)
|
||||
: base(message) {
|
||||
}
|
||||
|
||||
public OrchardCommandHostRetryException(LocalizedString message, Exception innerException)
|
||||
: base(message, innerException) {
|
||||
}
|
||||
|
||||
protected OrchardCommandHostRetryException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) {
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandHostEnvironment : IHostEnvironment {
|
||||
public CommandHostEnvironment() {
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -29,7 +44,7 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
public void ResetSiteCompilation() {
|
||||
throw new OrchardCoreException(T("A change of configuration requires the application to be restarted. Running the command again usually solves this problem."));
|
||||
throw new OrchardCommandHostRetryException(T("A change of configuration requires the host to be restarted."));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user