mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
fix: Using UTC for tracking scheduled events
This commit is contained in:
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
- Fixed a bug where color formatted console output on Net Standard was not raising the OnConsolePrint event
|
||||
- Simplifying ANSI color methods, better cross-platform color support
|
||||
- Console uses unicode for table drawing on Net Standard
|
||||
- Using UTC for tracking scheduled events, fixes issues with DST
|
||||
|
||||
## [10.3.0] - 2020-01-20
|
||||
### Changed
|
||||
|
||||
@@ -7,17 +7,17 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
{
|
||||
public event EventHandler OnScheduledRunTimeChanged;
|
||||
|
||||
private DateTime? m_NextRunTime;
|
||||
private DateTime? m_NextRunTimeUtc;
|
||||
|
||||
public DateTime? NextRunTime
|
||||
public DateTime? NextRunTimeUtc
|
||||
{
|
||||
get { return m_NextRunTime; }
|
||||
get { return m_NextRunTimeUtc; }
|
||||
private set
|
||||
{
|
||||
if (m_NextRunTime == value)
|
||||
if (m_NextRunTimeUtc == value)
|
||||
return;
|
||||
|
||||
m_NextRunTime = value;
|
||||
m_NextRunTimeUtc = value;
|
||||
|
||||
OnScheduledRunTimeChanged.Raise(this);
|
||||
}
|
||||
@@ -26,12 +26,12 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
public void Run()
|
||||
{
|
||||
RunFinal();
|
||||
NextRunTime = GetNextRunTime();
|
||||
NextRunTimeUtc = GetNextRunTimeUtc();
|
||||
}
|
||||
|
||||
public void UpdateNextRunTime()
|
||||
{
|
||||
NextRunTime = GetNextRunTime();
|
||||
NextRunTimeUtc = GetNextRunTimeUtc();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,6 +42,6 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
/// <summary>
|
||||
/// Runs after RunFinal in order to set the next run time of this action
|
||||
/// </summary>
|
||||
public abstract DateTime? GetNextRunTime();
|
||||
public abstract DateTime? GetNextRunTimeUtc();
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
try
|
||||
{
|
||||
Subscribe(action);
|
||||
m_Actions.InsertSorted(action, a => a.NextRunTime);
|
||||
m_Actions.InsertSorted(action, a => a.NextRunTimeUtc);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -96,15 +96,15 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
|
||||
private void TimerCallback()
|
||||
{
|
||||
DateTime currentTime = IcdEnvironment.GetLocalTime();
|
||||
DateTime currentTime = IcdEnvironment.GetUtcTime();
|
||||
IScheduledAction[] actionsToRun;
|
||||
|
||||
m_CriticalSection.Enter();
|
||||
try
|
||||
{
|
||||
actionsToRun = m_Actions
|
||||
.Where(a => a.NextRunTime <= currentTime && a.NextRunTime > m_LastRunTime)
|
||||
.OrderBy(a => a.NextRunTime)
|
||||
.Where(a => a.NextRunTimeUtc <= currentTime && a.NextRunTimeUtc > m_LastRunTime)
|
||||
.OrderBy(a => a.NextRunTimeUtc)
|
||||
.ToArray();
|
||||
}
|
||||
finally
|
||||
@@ -135,14 +135,14 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
m_CriticalSection.Enter();
|
||||
try
|
||||
{
|
||||
var action = m_Actions.FirstOrDefault(a => a.NextRunTime != null && a.NextRunTime > m_LastRunTime);
|
||||
if (action == null || action.NextRunTime == null)
|
||||
var action = m_Actions.FirstOrDefault(a => a.NextRunTimeUtc != null && a.NextRunTimeUtc > m_LastRunTime);
|
||||
if (action == null || action.NextRunTimeUtc == null)
|
||||
{
|
||||
m_Timer.Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
long msToNextAction = (long)(action.NextRunTime.Value - IcdEnvironment.GetLocalTime()).TotalMilliseconds;
|
||||
long msToNextAction = (long)(action.NextRunTimeUtc.Value - IcdEnvironment.GetUtcTime()).TotalMilliseconds;
|
||||
if (msToNextAction < 0)
|
||||
msToNextAction = 0;
|
||||
m_Timer.Reset(msToNextAction);
|
||||
@@ -195,7 +195,7 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
try
|
||||
{
|
||||
m_Actions.Remove(action);
|
||||
m_Actions.InsertSorted(action, a => a.NextRunTime);
|
||||
m_Actions.InsertSorted(action, a => a.NextRunTimeUtc);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ICD.Common.Utils.Services.Scheduler
|
||||
/// <summary>
|
||||
/// Gets the next time this action should be run
|
||||
/// </summary>
|
||||
DateTime? NextRunTime { get; }
|
||||
DateTime? NextRunTimeUtc { get; }
|
||||
|
||||
void Run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user