mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
update interval task trigger
This commit is contained in:
parent
5748112d5a
commit
b9638b484d
@ -1,6 +1,7 @@
|
|||||||
using MediaBrowser.Model.Events;
|
using MediaBrowser.Model.Events;
|
||||||
using MediaBrowser.Model.Tasks;
|
using MediaBrowser.Model.Tasks;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.ScheduledTasks
|
namespace MediaBrowser.Common.ScheduledTasks
|
||||||
@ -30,16 +31,7 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||||||
/// </value>
|
/// </value>
|
||||||
public TaskExecutionOptions TaskOptions { get; set; }
|
public TaskExecutionOptions TaskOptions { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
private DateTime _lastStartDate;
|
||||||
/// Gets or sets the first run delay.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The first run delay.</value>
|
|
||||||
public TimeSpan FirstRunDelay { get; set; }
|
|
||||||
|
|
||||||
public IntervalTrigger()
|
|
||||||
{
|
|
||||||
FirstRunDelay = TimeSpan.FromHours(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stars waiting for the trigger action
|
/// Stars waiting for the trigger action
|
||||||
@ -50,20 +42,21 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||||||
{
|
{
|
||||||
DisposeTimer();
|
DisposeTimer();
|
||||||
|
|
||||||
var triggerDate = lastResult != null ?
|
DateTime triggerDate;
|
||||||
lastResult.EndTimeUtc.Add(Interval) :
|
|
||||||
DateTime.UtcNow.Add(FirstRunDelay);
|
|
||||||
|
|
||||||
if (DateTime.UtcNow > triggerDate)
|
if (lastResult == null)
|
||||||
{
|
{
|
||||||
if (isApplicationStartup)
|
// Task has never been completed before
|
||||||
{
|
triggerDate = DateTime.UtcNow.AddHours(1);
|
||||||
triggerDate = DateTime.UtcNow.AddMinutes(1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
triggerDate = DateTime.UtcNow.AddMinutes(1);
|
triggerDate = new[] { lastResult.EndTimeUtc, _lastStartDate }.Max().Add(Interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DateTime.UtcNow > triggerDate)
|
||||||
|
{
|
||||||
|
triggerDate = DateTime.UtcNow.AddMinutes(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer = new Timer(state => OnTriggered(), null, triggerDate - DateTime.UtcNow, TimeSpan.FromMilliseconds(-1));
|
Timer = new Timer(state => OnTriggered(), null, triggerDate - DateTime.UtcNow, TimeSpan.FromMilliseconds(-1));
|
||||||
@ -98,8 +91,11 @@ namespace MediaBrowser.Common.ScheduledTasks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnTriggered()
|
private void OnTriggered()
|
||||||
{
|
{
|
||||||
|
DisposeTimer();
|
||||||
|
|
||||||
if (Triggered != null)
|
if (Triggered != null)
|
||||||
{
|
{
|
||||||
|
_lastStartDate = DateTime.UtcNow;
|
||||||
Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions));
|
Triggered(this, new GenericEventArgs<TaskExecutionOptions>(TaskOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user