且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Azure webjob功能的单独计划?

更新时间:2022-11-03 22:14:46

是的,您可以使用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:

具有计时器触发器和CRON表达式的连续Web作业