获取上次运行 Azure 函数的时间

Muu*_*ski 3 azure azure-functions

在 Visual Studio 2017 中,我创建了一个新的 Azure Function 项目,生成以下代码:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, TraceWriter log)
        {
            var lastRun = myTimer.ScheduleStatus.Last;

            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是关于lastRun变量的。是吗:

  1. 函数上次成功运行的时间
  2. 函数上次运行的时间,无论成功还是失败
  3. 完全是别的东西

我搜索了 Azure 文档,但没有找到有关 TimerInfo 对象属性的任何信息,因此了解此变量是否可用于了解函数上次运行时间会很有帮助。

小智 5

TimerInfo 对象的 ScheduleStatus 上的“Last”属性是上次函数计时器触发时的日期时间,无论函数运行状态是成功还是失败。当定时器触发时,它会触发定时器函数的执行。