Skip to content

Commit

Permalink
Add try catch block to address issue #56 (#57)
Browse files Browse the repository at this point in the history
* Add try catch block to fix issue #56

* Add space for formatting

* Add try catch block to fix issue #56
  • Loading branch information
CodeLover254 authored Jul 9, 2024
1 parent 973bd4b commit bacdb7a
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Source/VaultSharp.Extensions.Configuration/VaultChangeWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public VaultChangeWatcher(IConfiguration configuration, ILogger? logger = null)
}

this._logger = logger;

this._configProviders = configurationRoot.Providers.OfType<VaultConfigurationProvider>().Where(p => p.ConfigurationSource.Options.ReloadOnChange).ToList() !;
}

Expand All @@ -54,26 +54,34 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false);
if (stoppingToken.IsCancellationRequested)
{
break;
}

for (var j = 0; j < this._configProviders.Count(); j++)
try
{
var timer = timers[j];
timer -= minTime;
if (timer <= 0)
await Task.Delay(TimeSpan.FromSeconds(minTime), stoppingToken).ConfigureAwait(false);
if (stoppingToken.IsCancellationRequested)
{
this._configProviders.ElementAt(j).Load();
timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options.ReloadCheckIntervalSeconds;
break;
}
else

for (var j = 0; j < this._configProviders.Count(); j++)
{
timers[j] = timer;
var timer = timers[j];
timer -= minTime;
if (timer <= 0)
{
this._configProviders.ElementAt(j).Load();
timers[j] = this._configProviders.ElementAt(j).ConfigurationSource.Options
.ReloadCheckIntervalSeconds;
}
else
{
timers[j] = timer;
}
}
}
catch (Exception ex)
{
this._logger?.LogError(ex, $"An exception occurred in {nameof(VaultChangeWatcher)}");
}
}
}
}
Expand Down

0 comments on commit bacdb7a

Please sign in to comment.