public async Task OpenAsync(string correlationId) { if (_opened == true) { return; } // Create filter if it doesn't exist if (!Directory.Exists(_path)) { Directory.CreateDirectory(_path); } // Restart cleanup process if (_cleanupInterval != null) { _cleanupInterval.Stop(); } _cleanupInterval = new FixedRateTimer( () => { Cleanup(null); }, (int)_cleanupTimeout, (int)_cleanupTimeout ); _cleanupInterval.Start(); _opened = true; await Task.Delay(0); }
public async virtual void PerformMonitorAsync() { // 1. Check lock - if it's locked, don't process tracking records if (!_lock.TryAcquireLock(CorrelationId, $"ThroughputMonitor ({InternalCollectionNames})", TimerInterval)) { _logger.Warn(CorrelationId, $"PerformMonitorAsync: Skip to monitor throughput of '{InternalCollectionNames}' collection(s) (monitoring is locked). The next monitoring is scheduled to {DateTime.UtcNow.AddMilliseconds(TimerInterval).ToString()} UTC."); return; } // 2. Stop timer _timer?.Stop(); _logger.Trace(CorrelationId, $"PerformMonitorAsync: Wake-up to monitor throughput of '{InternalCollectionNames}' collection(s)."); foreach (var collectionName in CollectionNames) { // 3. Get throughput metrics for each collection var resourceUri = _metricsService.GetResourceUri(CorrelationId, ResourceGroup, AccountName, AccessKey, DatabaseName, collectionName); var throughputMetrics = await _metricsService.GetResourceMetricsAsync(CorrelationId, resourceUri, oDataQueryBuilder => oDataQueryBuilder .AddTime(DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(8)), DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(4)), MetricInterval.PT1M) .And() .AddMetric(CosmosDBMetric.Max_RUs_Per_Second)); // 4. Update throughput if needed await PerformUpdateThroughputAsync(CorrelationId, collectionName, throughputMetrics); } _logger.Trace(CorrelationId, $"PerformMonitorAsync: Completed to monitor throughput of '{InternalCollectionNames}' collection(s). The next monitoring is scheduled to {DateTime.UtcNow.AddMilliseconds(TimerInterval).ToString()} UTC."); // 5. Restart timer _timer?.Restart(); }
public Task CloseAsync(string correlationId) { _timer.Stop(); _logger.Trace(correlationId, "Dummy controller closed"); return(Task.Delay(0)); }
public Task CloseAsync(string correlationId) { if (_timer != null && _timer.IsStarted) { _timer.Stop(); } return(Task.Delay(0)); }
/// <summary> /// Closes component and frees used resources. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> public async Task CloseAsync(string correlationId) { // Log all remaining messages before closing Dump(); if (_timer != null) { _timer.Stop(); _timer = null; } _client = null; await Task.Delay(0); }