protected override async Task OnEnqueued(object sender, EnqueuedEventArgs <T> enqueuedEventArgs) { await base.OnEnqueued(sender, enqueuedEventArgs).AnyContext(); _timer.Run(); string customMetricName = GetCustomMetricName(enqueuedEventArgs.Entry.Value); if (!String.IsNullOrEmpty(customMetricName)) { await _metricsClient.CounterAsync(GetFullMetricName(customMetricName, "enqueued")).AnyContext(); } await _metricsClient.CounterAsync(GetFullMetricName("enqueued")).AnyContext(); }
public async Task CanRunConcurrent() { int hits = 0; Log.SetLogLevel <ScheduledTimer>(LogLevel.Trace); var timer = new ScheduledTimer(() => { int i = Interlocked.Increment(ref hits); _logger.Info($"Running {i}..."); return(Task.FromResult <DateTime?>(null)); }, minimumIntervalTime: TimeSpan.FromMilliseconds(250), loggerFactory: Log); for (int i = 0; i < 5; i++) { timer.Run(); await Task.Delay(5); } await Task.Delay(1000); Assert.Equal(2, hits); await Task.Delay(100); Assert.Equal(2, hits); }
public async Task CanRunWithMinimumInterval() { Log.SetLogLevel <ScheduledTimer>(LogLevel.Trace); int hits = 0; var timer = new ScheduledTimer(async() => { Interlocked.Increment(ref hits); await Task.Delay(50); return(null); }, minimumIntervalTime: TimeSpan.FromMilliseconds(50), loggerFactory: Log); timer.Run(); timer.Run(); await Task.Delay(1); Assert.Equal(1, hits); await Task.Delay(100); Assert.Equal(2, hits); }
public async Task CanRun() { Log.SetLogLevel <ScheduledTimer>(LogLevel.Trace); int hits = 0; var timer = new ScheduledTimer(async() => { Interlocked.Increment(ref hits); await Task.Delay(50); return(null); }, loggerFactory: Log); timer.Run(); await Task.Delay(1); Assert.Equal(1, hits); }