private void LogsFailedToSend(Exception e, IEnumerable <Log> logs) { try { FailedSendCount++; if (!logAgent.Configuration.MaxRetries.HasValue || RetryCount < logAgent.Configuration.MaxRetries.Value) { LogsToRetry = logs; RetryCount++; } else // we exceeded the max number of retries, time to move on { LogsToRetry = null; RetryCount = 0; logAgent.IncrementTotalLogsDropped(logs.Count()); } logAgent.BroadcastException(e); } finally { // don't forget to reset this! if (state == QueueManagerStates.Busy) { state = QueueManagerStates.Polling; } } }
void LogBatchCompleted(object sender, LogBatchCompletedEventArgs e) { if (e.Error == null) { try { logAgent.IncrementTotalLogsSent(e.Batch.Logs.Count()); logAgent.IncrementTotalBatchesSent(1); if (e.Result != null) { if (e.Result.IsEnabled.HasValue) { logAgent.State = e.Result.IsEnabled.Value ? BatchingLogAgent.BatchingLogAgentStates.Enabled : BatchingLogAgent.BatchingLogAgentStates.Disabled; } if (e.Result.QueuePollingInterval.HasValue && !IsThrottled) { QueuePollingInterval = e.Result.QueuePollingInterval.Value; } if (e.Result.ServerTime.HasValue) { if (!logAgent.ServerTimeOffset.HasValue && e.Batch.TimeStamp.HasValue) { logAgent.ServerTimeOffset = TimeSpan.FromTicks(e.Result.ServerTime.Value.Ticks - e.Batch.TimeStamp.Value); } } } // decrement the FailedSendCount FailedSendCount = Math.Max(FailedSendCount - 1, 0); try { if (BatchSendSuccess != null) { BatchSendSuccess(this, new BatchEventArgs(e.Batch)); } } catch { /* swollow */ } } catch (Exception ex) { LogBatchFailed(e.Batch, ex); } finally { // ALWAYS reset this! state = QueueManagerStates.Polling; } } else { LogBatchFailed(e.Batch, e.Error); } }
void pollingTimer_Tick(object sender) { lock (this) { if (state == QueueManagerStates.Polling) { state = QueueManagerStates.Busy; } else { return; // ignore call, we're already trying } } if (!ProcessQueue()) { state = QueueManagerStates.Polling; } }
public QueueManager(BatchingLogAgent LogAgent) { try { logAgent = LogAgent; dataClient = logAgent.Configuration.BatchAgent; dataClient.LogBatchCompleted += LogBatchCompleted; state = QueueManagerStates.Uninitialized; QueuePollingInterval = logAgent.Configuration.QueuePollingInterval; failedSendCount = 0; sendCount = 0; state = QueueManagerStates.Polling; pollingTimer = new System.Threading.Timer(pollingTimer_Tick, null, TimeSpan.FromSeconds(2), QueuePollingInterval); } catch { state = QueueManagerStates.Failed; throw; // re-throw the error } }
void LogBatchCompleted(object sender, LogBatchCompletedEventArgs e) { if (e.Error == null) { try { logAgent.IncrementTotalLogsSent(e.Batch.Logs.Count()); logAgent.IncrementTotalBatchesSent(1); if (e.Result != null) { if (e.Result.IsEnabled.HasValue) logAgent.State = e.Result.IsEnabled.Value ? BatchingLogAgent.BatchingLogAgentStates.Enabled : BatchingLogAgent.BatchingLogAgentStates.Disabled; if (e.Result.QueuePollingInterval.HasValue && !IsThrottled) QueuePollingInterval = e.Result.QueuePollingInterval.Value; if (e.Result.ServerTime.HasValue) { if (!logAgent.ServerTimeOffset.HasValue && e.Batch.TimeStamp.HasValue) { logAgent.ServerTimeOffset = TimeSpan.FromTicks(e.Result.ServerTime.Value.Ticks - e.Batch.TimeStamp.Value); } } } // decrement the FailedSendCount FailedSendCount = Math.Max(FailedSendCount - 1, 0); try { if (BatchSendSuccess != null) BatchSendSuccess(this, new BatchEventArgs(e.Batch)); } catch { /* swollow */ } } catch (Exception ex) { LogBatchFailed(e.Batch, ex); } finally { // ALWAYS reset this! state = QueueManagerStates.Polling; } } else { LogBatchFailed(e.Batch, e.Error); } }
private void LogsFailedToSend(Exception e, IEnumerable<Log> logs) { try { FailedSendCount++; if (!logAgent.Configuration.MaxRetries.HasValue || RetryCount < logAgent.Configuration.MaxRetries.Value) { LogsToRetry = logs; RetryCount++; } else // we exceeded the max number of retries, time to move on { LogsToRetry = null; RetryCount = 0; logAgent.IncrementTotalLogsDropped(logs.Count()); } logAgent.BroadcastException(e); } finally { // don't forget to reset this! if (state == QueueManagerStates.Busy) state = QueueManagerStates.Polling; } }
void pollingTimer_Tick(object sender) { lock (this) { if (state == QueueManagerStates.Polling) state = QueueManagerStates.Busy; else return; // ignore call, we're already trying } if (!ProcessQueue()) { state = QueueManagerStates.Polling; } }