Код: Выделить всё
public static void MyTimerJob([TimerTrigger("%MyTimerCRON%")] TimerInfo Timer, ILogger Log) {
// Function code
}
Чтобы иметь значение по умолчанию на случай, если при развертывании в настройках приложения ничего не установлено, я попытался добавить новый источник конфигурации, который будет распространяться на рабочие среды, выполнив действия, описанные в https://learn.microsoft. .com/en-us/azure/azure-functions/functions-dotnet-dependent-injection#customizing-configuration-sources:
- Добавление поставщиков в ConfigurationBuilder свойства IFunctionsConfigurationBuilder в ConfigurationAppConfiguration
Код: Выделить всё
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
FunctionsHostBuilderContext context = builder.GetContext();
builder.ConfigurationBuilder
.AddJsonFile(Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)
.AddEnvironmentVariables();
}
- Убедился, что файл скопирован в выходную папку приложения-функции в файле .csproj:
Код: Выделить всё
PreserveNewest
- И добавил соответствующий файл appsettings.json:
Код: Выделить всё
{
"MyTimerCRON": "* * * * *",
}
Код: Выделить всё
[2024-11-06T18:33:25.565Z] The Functions scale controller may not scale the following functions correctly because some configuration values were modified in an external startup class.
[2024-11-06T18:33:25.566Z] Function 'MyTimerJob' uses the modified key(s): %MyTimerCRON%
Код: Выделить всё
Environment.GetEnvironmentVariable("MyTimerCRON")
Подробнее здесь: https://stackoverflow.com/questions/791 ... tings-json