@@ -16,24 +16,27 @@ namespace SmartStore.Services.Tasks
1616
1717 public class DefaultTaskScheduler : DisposableObject , ITaskScheduler , IRegisteredObject
1818 {
19- private string _baseUrl ;
19+ private bool _intervalFixed ;
20+ private int _sweepInterval ;
21+ private string _baseUrl ;
2022 private System . Timers . Timer _timer ;
2123 private bool _shuttingDown ;
2224 private int _errCount ;
2325 private readonly ConcurrentDictionary < string , bool > _authTokens = new ConcurrentDictionary < string , bool > ( ) ;
2426
2527 public DefaultTaskScheduler ( )
2628 {
27- _timer = new System . Timers . Timer ( TimeSpan . FromMinutes ( 1 ) . TotalMilliseconds ) ;
29+ _sweepInterval = 1 ;
30+ _timer = new System . Timers . Timer ( ) ;
2831 _timer . Elapsed += Elapsed ;
2932
3033 HostingEnvironment . RegisterObject ( this ) ;
3134 }
3235
33- public TimeSpan SweepInterval
36+ public int SweepIntervalMinutes
3437 {
35- get { return TimeSpan . FromMilliseconds ( _timer . Interval ) ; }
36- set { _timer . Interval = value . TotalMilliseconds ; }
38+ get { return _sweepInterval ; }
39+ set { _sweepInterval = value ; }
3740 }
3841
3942 public string BaseUrl
@@ -49,16 +52,30 @@ public string BaseUrl
4952
5053 public void Start ( )
5154 {
52- lock ( _timer )
55+ if ( _timer . Enabled )
56+ return ;
57+
58+ lock ( _timer )
5359 {
5460 CheckUrl ( _baseUrl ) ;
61+ _timer . Interval = GetFixedInterval ( ) ;
5562 _timer . Start ( ) ;
5663 }
5764 }
5865
66+ private double GetFixedInterval ( )
67+ {
68+ // Gets seconds to next sweep minute
69+ int seconds = ( _sweepInterval * 60 ) - DateTime . Now . Second ;
70+ return seconds * 1000 ;
71+ }
72+
5973 public void Stop ( )
6074 {
61- lock ( _timer )
75+ if ( ! _timer . Enabled )
76+ return ;
77+
78+ lock ( _timer )
6279 {
6380 _timer . Stop ( ) ;
6481 }
@@ -98,7 +115,13 @@ private void Elapsed(object sender, System.Timers.ElapsedEventArgs e)
98115 {
99116 if ( _timer . Enabled )
100117 {
101- CallEndpoint ( _baseUrl + "/Sweep" ) ;
118+ if ( ! _intervalFixed )
119+ {
120+ _timer . Interval = TimeSpan . FromMinutes ( _sweepInterval ) . TotalMilliseconds ;
121+ _intervalFixed = true ;
122+ }
123+
124+ CallEndpoint ( _baseUrl + "/Sweep" ) ;
102125 }
103126 }
104127 finally
0 commit comments