用于排除定义时间的 Azure Function Cron 表达式

Azure Function Cron expression for excluding a defined time

我想在 Azure Functions 上做非常基本的 cron 作业。 我正在 Visual Studio 上编写函数,这些函数将被 dockerized 作业。 我的解决方案中有两个不同的 azure 函数。

  1. 每个月运行一次。 (刷新整个table)。
  2. 每五分钟运行一次。 (刷新的只是特征记录,不是历史记录。)

我的期望是函数不应相互阻塞。所以,他们不应该同时工作。 我的函数 cron 表达式是;

我不想 运行 每个月像 01/01/2021 00:00:00 那样运行 2。 如何从 function2 中排除时间?

没有直接的方法。

作为解决方法,您可以在 Function2 中添加 if else 代码块。比如在if block中,可以判断是否是01/01/2021 00:00:00这样的时间。如果是,则什么也不做。如果没有,则转到 else block 执行您的逻辑。

如下所示:

public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
    var the_time = DateTime.Now;

    //if the date is the first day of a month, and time is 00:00:00
    if(the_time.Day==1 && the_time.ToLongTimeString().Contains("00:00:00"))
    {
      //do nothing, don't write any code here.
    }
    else
   {
      //write your code logic here
   }

}