Azure 计划 Web 作业设置
Azure Schedule WebJob settings
如何 运行 基于 settings.json 而不是 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()}");
}
它始终使用硬编码值:
接下来 5 次出现 *the schedule (Cron: '0 * * * * ')
** 将是:
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%".
所以,在你的情况下,它会是这样的:
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()}");
}
如何 运行 基于 settings.json 而不是 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()}");
}
它始终使用硬编码值: 接下来 5 次出现 *the schedule (Cron: '0 * * * * ')
** 将是:
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%".
所以,在你的情况下,它会是这样的:
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()}");
}