Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reload on empty or missing key #129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private async Task DoLoad(CancellationToken cancellationToken)

if (result.HasValue())
{
SetData(result);
Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig);
}
else if (!_source.Optional)
{
Expand Down Expand Up @@ -134,9 +134,9 @@ private async Task PollingLoop(CancellationToken cancellationToken)
{
var result = await GetKvPairs(true, cancellationToken).ConfigureAwait(false);

if (result.HasValue() && result.LastIndex > _lastIndex)
if (result.LastIndex > _lastIndex)
{
SetData(result);
Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig);
OnReload();
}

Expand All @@ -154,11 +154,6 @@ private async Task PollingLoop(CancellationToken cancellationToken)
}
}

private void SetData(QueryResult<KVPair[]> result)
{
Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig);
}

private void SetLastIndex(QueryResult result)
{
_lastIndex = result.LastIndex == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
using System.Linq;
using System.Net;
using Consul;
using Winton.Extensions.Configuration.Consul.Parsers;

namespace Winton.Extensions.Configuration.Consul.Extensions
{
internal static class KVPairQueryResultExtensions
{
internal static bool HasValue(this QueryResult<KVPair[]> result)
internal static bool HasValue(this QueryResult<KVPair[]>? result)
{
return result != null
&& result.StatusCode != HttpStatusCode.NotFound
Expand All @@ -24,7 +23,7 @@ internal static Dictionary<string, string> ToConfigDictionary(
this QueryResult<KVPair[]> result,
Func<KVPair, IEnumerable<KeyValuePair<string, string>>> convertConsulKVPairToConfig)
{
return (result.Response ?? new KVPair[0])
return (result.Response ?? Array.Empty<KVPair>())
.Where(kvp => kvp.HasValue())
.SelectMany(convertConsulKVPairToConfig)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase);
Expand Down