From 30ac0b78f3d8293a46c0e831cdf57f9d918c51bf Mon Sep 17 00:00:00 2001 From: solmetricchris Date: Mon, 22 Jun 2015 14:39:46 -0700 Subject: [PATCH] expose maxRetries value via optional parameter --- Src/Metrics/MetricsConfig.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Src/Metrics/MetricsConfig.cs b/Src/Metrics/MetricsConfig.cs index 5d2a6e76..48c92c6d 100644 --- a/Src/Metrics/MetricsConfig.cs +++ b/Src/Metrics/MetricsConfig.cs @@ -45,13 +45,13 @@ public MetricsConfig(MetricsContext context) /// GET /text => metrics in human readable text format /// /// prefix where to start HTTP endpoint + /// maximum number of attempts to start the http listener. Note the retry time between attemps is dependent on this value /// Chain-able configuration object. - public MetricsConfig WithHttpEndpoint(string httpUriPrefix) + public MetricsConfig WithHttpEndpoint(string httpUriPrefix, int maxRetries = 3) { if (!isDisabled) { - const int MaxRetries = 3; - var retries = MaxRetries; + var retries = maxRetries; do { @@ -62,9 +62,9 @@ public MetricsConfig WithHttpEndpoint(string httpUriPrefix) } this.listener = new MetricsHttpListener(httpUriPrefix, this.context.DataProvider, this.healthStatus); this.listener.Start(); - if (retries != MaxRetries) + if (retries != maxRetries) { - log.InfoFormat("HttpListener started successfully after {0} retries", MaxRetries - retries); + log.InfoFormat("HttpListener started successfully after {0} retries", maxRetries - retries); } retries = 0; } @@ -73,13 +73,13 @@ public MetricsConfig WithHttpEndpoint(string httpUriPrefix) retries--; if (retries > 0) { - log.WarnException("Unable to start HTTP Listener. Sleeping for {0} sec and retrying {1} more times", x, MaxRetries - retries, retries); - Thread.Sleep(1000 * (MaxRetries - retries)); + log.WarnException("Unable to start HTTP Listener. Sleeping for {0} sec and retrying {1} more times", x, maxRetries - retries, retries); + Thread.Sleep(1000 * (maxRetries - retries)); } else { MetricsErrorHandler.Handle(x, - string.Format("Unable to start HTTP Listener. Retried {0} times, giving up...", MaxRetries)); + string.Format("Unable to start HTTP Listener. Retried {0} times, giving up...", maxRetries)); } }