BackgroundTaskRunner - add Hosted option, refactor some tasks

Conflicts:
	src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs
This commit is contained in:
Stephan
2015-07-10 15:52:58 +02:00
parent 0f56fa4baa
commit 34a9eef8b8
5 changed files with 27 additions and 24 deletions

View File

@@ -884,14 +884,6 @@ namespace Umbraco.Tests.Scheduling
}
public override bool RunsOnShutdown { get { return false; } }
protected override void Dispose(bool disposing)
{
Disposed = true;
base.Dispose(disposing);
}
public bool Disposed { get; private set; }
}
private class MyTask : BaseTask

View File

@@ -90,7 +90,8 @@ namespace Umbraco.Web.Scheduling
_options = options;
_logPrefix = "[" + name + "] ";
HostingEnvironment.RegisterObject(this);
if (options.Hosted)
HostingEnvironment.RegisterObject(this);
if (options.AutoStart)
StartUp();

View File

@@ -15,6 +15,8 @@ namespace Umbraco.Web.Scheduling
LongRunning = false;
KeepAlive = false;
AutoStart = false;
PreserveRunningTask = false;
Hosted = true;
}
/// <summary>
@@ -36,9 +38,16 @@ namespace Umbraco.Web.Scheduling
public bool AutoStart { get; set; }
/// <summary>
/// Gets or setes a value indicating whether the running task should be preserved
/// Gets or sets a value indicating whether the running task should be preserved
/// once completed, or reset to null. For unit tests.
/// </summary>
public bool PreserveRunningTask { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the runner should register with (and be
/// stopped by) the hosting. Otherwise, something else should take care of stopping
/// the runner. True by default.
/// </summary>
public bool Hosted { get; set; }
}
}

View File

@@ -63,15 +63,22 @@ namespace Umbraco.Web.Scheduling
protected virtual void Dispose(bool disposing)
{
// lock on _latch instead of creating a new object as _timer is
if (disposing == false) return;
// lock on _latch instead of creating a new object as _latch is
// private, non-null, readonly - so safe here
lock (_latch)
{
if (_disposed) return;
_disposed = true;
_latch.Dispose();
_latch.Dispose();
DisposeResources();
}
}
protected virtual void DisposeResources()
{ }
public bool Disposed { get { return _disposed; } }
}
}

View File

@@ -84,19 +84,13 @@ namespace Umbraco.Web.Scheduling
/// and returning a value indicating whether to repeat the task.</returns>
public abstract Task<bool> PerformRunAsync(CancellationToken token);
protected override void Dispose(bool disposing)
protected override void DisposeResources()
{
// lock on _timer instead of creating a new object as _timer is
// private, non-null, readonly - so safe here
lock (_timer)
{
if (_disposed) return;
_disposed = true;
base.DisposeResources();
// stop the timer
_timer.Change(Timeout.Infinite, Timeout.Infinite);
_timer.Dispose();
}
// stop the timer
_timer.Change(Timeout.Infinite, Timeout.Infinite);
_timer.Dispose();
}
}
}