PE tasks list init and start background timer after PE tasks.

Fixes #6742
This commit is contained in:
jtkech
2016-05-26 21:58:31 +02:00
committed by Sébastien Ros
parent a90bdde699
commit 147b4fd05b
6 changed files with 31 additions and 6 deletions

View File

@@ -203,6 +203,8 @@ namespace Orchard.Tests.Modules.Comments.Services {
public class ProcessingEngineStub : IProcessingEngine {
public void Initialize() { }
public string AddTask(ShellSettings shellSettings, ShellDescriptor shellDescriptor, string messageName, Dictionary<string, object> parameters) {
return "";
}

View File

@@ -147,6 +147,10 @@ namespace Orchard.Environment {
// Load all tenants, and activate their shell.
if (allSettings.Any()) {
Parallel.ForEach(allSettings, settings => {
_processingEngine.Initialize();
ShellContext context = null;
for (var i = 0; i <= Retries; i++) {
// Not the first attempt, wait for a while ...
@@ -157,10 +161,10 @@ namespace Orchard.Environment {
}
try {
var context = CreateShellContext(settings);
context = CreateShellContext(settings);
ActivateShell(context);
// If everything went well, return to stop the retry loop
// If everything went well, break the retry loop
break;
}
catch (Exception ex) {
@@ -172,12 +176,18 @@ namespace Orchard.Environment {
Logger.Error(ex, "A tenant could not be started: " + settings.Name + " Attempt number: " + i);
}
}
}
while (_processingEngine.AreTasksPending()) {
Logger.Debug("Processing pending task after activate Shell");
_processingEngine.ExecuteNextTask();
if (_processingEngine.AreTasksPending()) {
context.Shell.Sweep.Terminate();
while (_processingEngine.AreTasksPending()) {
Logger.Debug("Processing pending task after activate Shell");
_processingEngine.ExecuteNextTask();
}
context.Shell.Sweep.Activate();
}
});
}

View File

@@ -50,6 +50,7 @@ namespace Orchard.Environment {
}
public ILogger Logger { get; set; }
public ISweepGenerator Sweep { get { return _sweepGenerator; } }
public void Activate() {
var appBuilder = new AppBuilder();

View File

@@ -1,6 +1,9 @@
using Orchard.Tasks;
namespace Orchard.Environment {
public interface IOrchardShell {
void Activate();
void Terminate();
ISweepGenerator Sweep { get; }
}
}

View File

@@ -22,6 +22,10 @@ namespace Orchard.Environment.State {
_entries = new ContextState<IList<Entry>>("DefaultProcessingEngine.Entries", () => new List<Entry>());
}
public void Initialize() {
_entries.SetState(new List<Entry>());
}
public string AddTask(ShellSettings shellSettings, ShellDescriptor shellDescriptor, string eventName, Dictionary<string, object> parameters) {
var entry = new Entry {

View File

@@ -6,6 +6,11 @@ namespace Orchard.Environment.State
{
public interface IProcessingEngine
{
/// <summary>
/// Init a new tasks list in the http context or in a new logical context.
/// </summary>
void Initialize();
/// <summary>
/// Queue an event to fire inside of an explicitly decribed shell context
/// </summary>