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

Configuration Refresher with Timer Trigger #924

Closed
JFulfordMS opened this issue May 30, 2024 · 7 comments
Closed

Configuration Refresher with Timer Trigger #924

JFulfordMS opened this issue May 30, 2024 · 7 comments

Comments

@JFulfordMS
Copy link

Curious if this is a pending feature or a bug but a Timer Trigger referencing a schedule from an App Configuration store doesn't get refreshed values and continues to run at the initial schedule when the function last started. I've validated that the function itself is successfully refreshing the values.

@mrm9084
Copy link
Member

mrm9084 commented May 30, 2024

@JFulfordMS, can you provide more info like which of our packages you are using and what the version info is.

@JFulfordMS
Copy link
Author

@JFulfordMS, can you provide more info like which of our packages you are using and what the version info is.

I'm using Azure.Data.AppConfiguration 1.4.1 and AzureAppConfiguration 7.2.0.

@jimmyca15
Copy link
Member

@JFulfordMS

To help me make sure I understand what you're talking about, can you tell/show me how you get the Function to use a schedule defined in App Configuration?

@JFulfordMS
Copy link
Author

JFulfordMS commented Jun 3, 2024

Sure, here is a way to test it. I set the parameter of "CdataHelper:Schedule" in an app configuration store to "*/30 * * * * *
". Then reference it in the TimerTrigger constructor. The function changes the value of the parameter to "*/5 * * * * *
" and successfully gets the updated value on the next run, but the timer still only runs every 30 seconds.

`

    private readonly IConfiguration _configuration;
    private readonly IConfigurationRefresher _configurationRefresher;
    private readonly ConfigurationClient configurationClient;

    public CdataJobFunctions(IConfiguration configuration, IConfigurationRefresherProvider refresherProvider)
    {
        _configuration = configuration;
        _configurationRefresher = refresherProvider.Refreshers.First();
        configurationClient = new ConfigurationClient(Environment.GetEnvironmentVariable("ConfigConnectionString"));
       
    }
    static HttpClient httpClient = new HttpClient();

    [FunctionName("DoUpdate")]
    public async Task Run([TimerTrigger("%CdataHelper:Schedule%")] TimerInfo myTimer, ILogger log)
    {

        log.LogInformation($"Running at: {DateTime.Now}");

        log.LogInformation(_configuration["CdataHelper:Schedule"]);
      
        var setting = configurationClient.SetConfigurationSetting("CdataHelper:Schedule", "*/5 * * * * *");
        await _configurationRefresher.TryRefreshAsync();

    }

`

[2024-06-03T12:10:30.006Z] Executing 'DoUpdate' (Reason='Timer fired at 2024-06-03T08:10:30.0052795-04:00', Id=84a6331c-e7c1-46f0-8ac5-e872ac43b9cc)
[2024-06-03T12:10:30.008Z] Running at: 6/3/2024 8:10:30 AM
[2024-06-03T12:10:30.008Z] */30 * * * * *
[2024-06-03T12:10:30.595Z] Executed 'DoUpdate' (Succeeded, Id=84a6331c-e7c1-46f0-8ac5-e872ac43b9cc, Duration=590ms)
[2024-06-03T12:11:00.010Z] Executing 'DoUpdate' (Reason='Timer fired at 2024-06-03T08:11:00.0094870-04:00', Id=9015ccad-a249-41f3-b1e1-cdb49d616c2d)
[2024-06-03T12:11:00.014Z] Running at: 6/3/2024 8:11:00 AM
[2024-06-03T12:11:00.015Z] */5 * * * * *
[2024-06-03T12:11:00.178Z] Executed 'DoUpdate' (Succeeded, Id=9015ccad-a249-41f3-b1e1-cdb49d616c2d, Duration=168ms)
[2024-06-03T12:11:30.011Z] Running at: 6/3/2024 8:11:30 AM
[2024-06-03T12:11:30.012Z] */5 * * * * *
[2024-06-03T12:11:30.500Z] Executed 'DoUpdate' (Succeeded, Id=39db3973-6db1-490c-99de-3381840462a1, Duration=491ms)

@zhenlan
Copy link
Contributor

zhenlan commented Jul 4, 2024

The trigger uses the app setting binding expression of the Azure Functions. While your code can pick up the latest value in App Configuration, I suspect Azure Functions won't pick up the new setting without the function app being restarted (just like how app setting works in Azure Functions).

@zhenlan
Copy link
Contributor

zhenlan commented Aug 9, 2024

Closing. Please reopen it if there are further questions.

@zhenlan zhenlan closed this as completed Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants