BackgroundTaskRunner - add Hosted option, refactor some tasks
Conflicts: src/Umbraco.Web/Scheduling/BackgroundTaskRunner.cs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user