Azure webjob功能的单独计划? [英] Separate schedules for Azure webjob functions?
本文介绍了Azure webjob功能的单独计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为Azure Webjob中的各个非触发功能设置单独的计划?我问是因为我想在一天中的不同时间和不同的时间间隔运行六个独立的任务,并且不想为每个任务创建一个单独的项目.
Is it possible to set up separate schedules for individual non-triggered functions in an Azure webjob? I ask because I have half a dozen individual tasks I'd like to run at different times of the day and at different intervals and don't want to create a separate project for each.
推荐答案
是的,您可以使用TimerTriggerAttribute
- Azure WebJobs SDK Extensions
- nuget download page
这是示例代码:
public class Program
{
static void Main(string[] args)
{
JobHostConfiguration config = new JobHostConfiguration();
// Add Triggers for Timer Trigger.
config.UseFiles(filesConfig);
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
// Function triggered by a timespan schedule every 15 sec.
public static void TimerJob([TimerTrigger("00:00:15")] TimerInfo timerInfo,
TextWriter log)
{
log.WriteLine("1st scheduled job fired!");
}
// Function triggered by a timespan schedule every minute.
public static void TimerJob([TimerTrigger("00:01:00")] TimerInfo timerInfo,
TextWriter log)
{
log.WriteLine("2nd scheduled job fired!");
}
}
您还可以使用CRON表达式指定何时触发函数:
You can also use a CRON expression to specify when to trigger the function:
这篇关于Azure webjob功能的单独计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文