Updates BackgroundTaskRunner to ensure canceled or skipped tasks are disposed, updated tests to reflect
This commit is contained in:
@@ -273,22 +273,25 @@ namespace Umbraco.Tests.Scheduling
|
||||
{
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
public override void PerformRun()
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class BaseTask : IBackgroundTask
|
||||
{
|
||||
public bool WasCancelled { get; set; }
|
||||
|
||||
public Guid UniqueId { get; protected set; }
|
||||
|
||||
public abstract void Run();
|
||||
public abstract void PerformRun();
|
||||
public void Run()
|
||||
{
|
||||
PerformRun();
|
||||
Ended = DateTime.Now;
|
||||
}
|
||||
public Task RunAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -299,7 +302,10 @@ namespace Umbraco.Tests.Scheduling
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public abstract void Cancel();
|
||||
public virtual void Cancel()
|
||||
{
|
||||
WasCancelled = true;
|
||||
}
|
||||
|
||||
public DateTime Queued { get; set; }
|
||||
public DateTime Started { get; set; }
|
||||
@@ -307,7 +313,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
Ended = DateTime.Now;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,26 +8,6 @@ using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Web.Scheduling
|
||||
{
|
||||
|
||||
internal class BackgroundTaskRunnerOptions
|
||||
{
|
||||
public BackgroundTaskRunnerOptions()
|
||||
{
|
||||
DedicatedThread = false;
|
||||
PersistentThread = false;
|
||||
OnlyProcessLastItem = false;
|
||||
}
|
||||
|
||||
public bool DedicatedThread { get; set; }
|
||||
public bool PersistentThread { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this is true, the task runner will skip over all items and only process the last/final
|
||||
/// item registered
|
||||
/// </summary>
|
||||
public bool OnlyProcessLastItem { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used to create a background task runner which will stay alive in the background of and complete
|
||||
/// any tasks that are queued. It is web aware and will ensure that it is shutdown correctly when the app domain
|
||||
@@ -174,7 +154,8 @@ namespace Umbraco.Web.Scheduling
|
||||
//skip if this is not the last
|
||||
if (_options.OnlyProcessLastItem && _tasks.Count > 0)
|
||||
{
|
||||
//NOTE: don't raise canceled event, we're shutting down
|
||||
//NOTE: don't raise canceled event, we're shutting down, just dispose
|
||||
remainingTask.Dispose();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -372,6 +353,9 @@ namespace Umbraco.Web.Scheduling
|
||||
{
|
||||
var handler = TaskCancelled;
|
||||
if (handler != null) handler(this, e);
|
||||
|
||||
//dispose it
|
||||
e.Task.Dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
23
src/Umbraco.Web/Scheduling/BackgroundTaskRunnerOptions.cs
Normal file
23
src/Umbraco.Web/Scheduling/BackgroundTaskRunnerOptions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Umbraco.Web.Scheduling
|
||||
{
|
||||
internal class BackgroundTaskRunnerOptions
|
||||
{
|
||||
//TODO: Could add options for using a stack vs queue if required
|
||||
|
||||
public BackgroundTaskRunnerOptions()
|
||||
{
|
||||
DedicatedThread = false;
|
||||
PersistentThread = false;
|
||||
OnlyProcessLastItem = false;
|
||||
}
|
||||
|
||||
public bool DedicatedThread { get; set; }
|
||||
public bool PersistentThread { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this is true, the task runner will skip over all items and only process the last/final
|
||||
/// item registered
|
||||
/// </summary>
|
||||
public bool OnlyProcessLastItem { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -498,6 +498,7 @@
|
||||
<Compile Include="Mvc\UmbracoVirtualNodeRouteHandler.cs" />
|
||||
<Compile Include="Routing\CustomRouteUrlProvider.cs" />
|
||||
<Compile Include="Routing\UrlProviderExtensions.cs" />
|
||||
<Compile Include="Scheduling\BackgroundTaskRunnerOptions.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearCsrfCookiesAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\ClearMediaXmlCacheForDeletedItemsAfterUpgrade.cs" />
|
||||
<Compile Include="Strategies\Migrations\EnsureListViewDataTypeIsCreated.cs" />
|
||||
|
||||
Reference in New Issue
Block a user