public WebhookReceiverTests() { _payloadQueue = new PayloadQueue(); _payloadQueue.Clear(); var server = new TestServer(new WebHostBuilder().UseStartup <Startup>()); _client = server.CreateClient(); }
void Flush(object isCalledFromTimer) { if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down { return; } var lockTaken = false; try { lockTaken = Monitor.TryEnter(_flushingLock); // the lock prevents calls to Flush from stacking up, but we skip this check if we're in draining mode if (!lockTaken && !ShutdownCalled) { Debug.WriteLine("BosunReporter: Flush already in progress (skipping)."); return; } if (!ShutdownCalled && _skipFlushes > 0) { _skipFlushes--; return; } bool any; do { any = false; any |= FlushPayload("/api/put", _localMetricsQueue); if (EnableExternalCounters) { any |= FlushPayload("/api/count", _externalCounterQueue); } else { _externalCounterQueue.Clear(); } } while (any); } catch (Exception ex) { // there was a problem flushing - back off for the next five seconds (Bosun may simply be restarting) _skipFlushes = 4; PossiblyLogException(ex); } finally { if (lockTaken) { Monitor.Exit(_flushingLock); } } }
public WebhookReceiverTests() { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); var payloadQueueSettings = configuration.GetSection("PayloadQueueSettings").Get <PayloadQueueSettings>(); _payloadQueue = new PayloadQueue(payloadQueueSettings); _payloadQueue.Clear(); var server = new TestServer(new WebHostBuilder().UseConfiguration(configuration).UseStartup <Startup>()); _client = server.CreateClient(); }
void Flush(object isCalledFromTimer) { if ((bool)isCalledFromTimer && ShutdownCalled) // don't perform timer actions if we're shutting down { return; } if (!HasAnythingToFlush()) { return; } var lockTaken = false; try { lockTaken = Monitor.TryEnter(_flushingLock); // the lock prevents calls to Flush from stacking up, but we skip this check if we're in draining mode if (!lockTaken && !ShutdownCalled) { Debug.WriteLine("BosunReporter: Flush already in progress (skipping)."); return; } if (!HasAnythingToFlush()) { return; } if (!TryGetBosunUrl(out var url)) { Debug.WriteLine("BosunReporter: BosunUrl is null. Dropping data."); _localMetricsQueue.Clear(); _externalCounterQueue.Clear(); _readyToFlushMetadata = false; return; } FlushPayloadQueue(_localMetricsQueue, url); if (EnableExternalCounters) { FlushPayloadQueue(_externalCounterQueue, url); } else { _externalCounterQueue.Clear(); } if (_readyToFlushMetadata) { PostMetadata(url); } } catch (Exception ex) { // this should never actually hit, but it's a nice safeguard since an uncaught exception on a background thread will crash the process. SendExceptionToHandler(ex); } finally { if (lockTaken) { Monitor.Exit(_flushingLock); } } }
public void Dispose() { _payloadQueue.Clear(); }