-
Notifications
You must be signed in to change notification settings - Fork 112
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
Using the CacheExpirationInterval option does not work on a console app #252
Comments
Hello @pregoli , For console apps (and Azure Functions), I believe the only way to refresh is to explicitly call TryRefreshAsync. See the Azure Functions Guide for an example. I'll continue to look into this, because it's not clear to me why the refresh is restricted in this way. |
Thanks for your reply @rossgrambo but I think refreshing explicitely is not the way We or The consumers of this library aim to go. You could end up refreshing on a schedule way even when there's no need to refresh it because no changes happened on FFs values. I think the current behavior is due to the refresh/trigger is happening within the ASP.Net pipeline middleware while in the backgroundservice is not. Please keep us in the loop. Thanks! |
After syncing with some other members, I see now why it's built the way it is. Here's a summary of it, only a couple parts might be of interest to you. The library that handles dynamic configurations ( This library reads from our server, and places it into Configuration for the app. Configuration is a part of .NET and can be thought of as a dictionary for traversing json-like data. Configuration doesn't have a hook we could add a refresh check in, so when refreshing was built it used a timer approach and would update the config in a scheduled way. As you called out, this led to a bunch of refreshes for no reason. This was especially bad for stale apps, that continued to ping us without users or purpose. The timer was replaced with a middleware. The middleware is setup via Console apps don't have a consistent workflow we can add a hook to in the same way. So the current state is to leave it to the developer to trigger the refresh appropriately. Allowing a flag to change mid-execution might not make sense for some apps. Here's a guide for now to setup refreshing for a .NET Core app: https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-dotnet-core?tabs=core6x All of that to say, I think you should add I could see a world where we add a |
Closing this for now. |
We need to get a the latest feature flag value every time we read from Azure App configuration - FeatureManager.
By using:
.UseFeatureFlags(options => options.CacheExpirationInterval = TimeSpan.FromSeconds(15))
The above extension works as expected when used within an API project.
The same approach does NOT work on a console app.
Extra info: The extensions AddAzureAppConfiguration & UseAzureAppConfiguration are correctly used.
Steps to reproduce:
builder.Services.AddHostedService<MyHostedService>();
) as BackgroundService3.1
Services.AddAzureAppConfiguration()
3.2
app.UseAzureAppConfiguration();
3.3
.UseFeatureFlags(options => options.CacheExpirationInterval = TimeSpan.FromSeconds(15))
while (!stoppingToken.IsCancellationRequested) { var featureTestEnabled = await _featureManager.IsEnabledAsync("featureTest") if (featureTestEnabled) { //do something } else { //do something else } await timer.WaitForNextTickAsync(stoppingToken); }
The text was updated successfully, but these errors were encountered: