How can I run a webjob based off of settings.json instead of hardcoded value in TimerTrigger?
settings.json
{
//Runs at 9:30 AM every day
"schedule": "0 30 9 * * *"
}
Functions.cs
[Singleton]
public static void TimerTick([TimerTrigger("0 * * * * *")] TimerInfo myTimer)
{
Console.WriteLine($"Hello at {DateTime.UtcNow.ToString()}");
}
It always uses the hard coded value: The next 5 occurrences of *the schedule (Cron: '0 * * * * ')
** will be:
How to do that is explained in the docs:
You can put the schedule expression in an app setting and set this property to the app setting name wrapped in % signs, as in this example: "%ScheduleAppSetting%".
So, in your case it would be something like this:
settings.json
{
//Runs at 9:30 AM every day
"schedule": "0 30 9 * * *"
}
Functions.cs
[Singleton]
public static void TimerTick([TimerTrigger("%schedule%")] TimerInfo myTimer)
{
Console.WriteLine($"Hello at {DateTime.UtcNow.ToString()}");
}