private async Task BulkSubmitAsync(IList <Event> events) { var cts = new CancellationTokenSource(_config.HttpClientTimeout); var jsonEvents = ""; try { jsonEvents = JsonConvert.SerializeObject(events.ToList(), Formatting.None); Logger.LogDebug("Submitting " + events.Count + " events to " + _uri.AbsoluteUri + " with json: " + jsonEvents); await SendEventsAsync(jsonEvents, cts); } catch (Exception e) { // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); Logger.LogDebug("Error sending events: " + Util.ExceptionMessage(e) + " waiting 1 second before retrying."); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); cts = new CancellationTokenSource(_config.HttpClientTimeout); try { Logger.LogDebug("Submitting " + events.Count + " events to " + _uri.AbsoluteUri + " with json: " + jsonEvents); await SendEventsAsync(jsonEvents, cts); } catch (TaskCanceledException tce) { if (tce.CancellationToken == cts.Token) { //Indicates the task was cancelled by something other than a request timeout Logger.LogError(string.Format("Error Submitting Events using uri: '{0}' '{1}'", _uri.AbsoluteUri, Util.ExceptionMessage(tce)) + tce + " " + tce.StackTrace); } else { //Otherwise this was a request timeout. Logger.LogError("Timed out trying to send " + events.Count + " events after " + _config.HttpClientTimeout); } // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); } catch (Exception ex) { Logger.LogError(string.Format("Error Submitting Events using uri: '{0}' '{1}'", _uri.AbsoluteUri, Util.ExceptionMessage(ex)) + ex + " " + ex.StackTrace); // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); } } }
internal FeatureRequestor(Configuration config) { _config = config; _allUri = new Uri(config.BaseUri.AbsoluteUri + "sdk/latest-all"); _flagsUri = new Uri(config.BaseUri.AbsoluteUri + "sdk/latest-flags/"); _segmentsUri = new Uri(config.BaseUri.AbsoluteUri + "sdk/latest-segments/"); _httpClient = config.HttpClient(); }
// Returns a dictionary of the latest flags, or null if they have not been modified. Throws an exception if there // was a problem getting flags. internal async Task <IDictionary <string, FeatureFlag> > MakeAllRequestAsync() { var cts = new CancellationTokenSource(_config.HttpClientTimeout); try { return(await FetchFeatureFlagsAsync(cts)); } catch (Exception e) { // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); Logger.LogDebug("Error getting feature flags: " + Util.ExceptionMessage(e) + " waiting 1 second before retrying."); Thread.Sleep(TimeSpan.FromSeconds(1)); cts = new CancellationTokenSource(_config.HttpClientTimeout); try { return(await FetchFeatureFlagsAsync(cts)); } catch (TaskCanceledException tce) { // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); if (tce.CancellationToken == cts.Token) { //Indicates the task was cancelled by something other than a request timeout throw tce; } //Otherwise this was a request timeout. throw new Exception("Get Features with URL: " + _uri.AbsoluteUri + " timed out after : " + _config.HttpClientTimeout); } catch (Exception ex) { // Using a new client after errors because: https://github.com/dotnet/corefx/issues/11224 _httpClient?.Dispose(); _httpClient = _config.HttpClient(); throw ex; } } }
internal EventProcessor(Configuration config) { _config = config; _httpClient = config.HttpClient(); _queue = new BlockingCollection <Event>(_config.EventQueueCapacity); _timer = new Timer(SubmitEvents, null, _config.EventQueueFrequency, _config.EventQueueFrequency); _uri = new Uri(_config.EventsUri.AbsoluteUri + "bulk"); }
internal FeatureRequestor(Configuration config) { _config = config; _uri = new Uri(config.BaseUri.AbsoluteUri + "sdk/latest-flags"); _httpClient = config.HttpClient(); }