The user inputs the CRON expression from an interface. The function app should update the appsettings to reflect the user input.
My current approach
The TimerTrigger function with schedule
appsetting
[FunctionName("Cleanup")]
public static async Task Run([TimerTrigger("%schedule%")]TimerInfo myTimer, ILogger log)
{
// Get the connection string from app settings and use it to create a connection.
var str = Environment.GetEnvironmentVariable("db_connection");
log.LogInformation($"db_connection : {str}");
}
Setting the schedule
appsetting via environment variable
[FunctionName("SetConfig")]
public static async Task<HttpResponseMessage> SetConfig([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req)
{
HistoryLogDeleteConfigDto data = await req.Content.ReadAsAsync<HistoryLogDeleteConfigDto>();
Environment.SetEnvironmentVariable("schedule", data.Schedule);
return req.CreateResponse(HttpStatusCode.OK);
}
local.settings.json file
"Values": {
"db_connection": "Server=DESKTOP-DFJ3PBT;Database=CovalentLogger;Trusted_Connection=True;MultipleActiveResultSets=true",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"schedule": "*/20 * * * * *"
}
POSTMAN request body to update the schedule
appsetting
{
"Schedule": "*/30 * * * * *"
}
But no luck. After sending the request from postman to update the setting, if I access the azure portal function app setting I still can see the old value.
But if I query the environmnet variable like below
Environment.GetEnvironmentVariable("schedule", EnvironmentVariableTarget.Process)
I can see the new expression. But in Azure portal function appsetting it stills the old value. So the job still executes based on the old schedule.
Where have I gone wrong? Thank you