永远不会执行的Azure功能作业

时间:2019-06-12 06:54:59

标签: azure cron azure-functions

我正在尝试填充一个CRON表达式,该表达式将伪装成永远不会执行(至少在这个生命周期中不会如此)。

我遇到了这个问题 https://stackoverflow.com/questions/8324306/cron-job-that-will-never-execute

但是该问题中的每个表达式都给出一个例外 Microsoft.Azure.WebJobs.Host: Error indexing method 'Cleanup'. Microsoft.Azure.WebJobs.Extensions: The schedule expression '0 0 5 31 2 ?' was not recognized as a valid cron expression or timespan string.

可以满足上述关于Azure函数的期望的表达式有哪些?

谢谢。

3 个答案:

答案 0 :(得分:3)

请检查Azure CRON expression,它是:

{second} {minute} {hour} {day} {month} {day-of-week}

它使用NCronTab库来解释CRON表达式。在github页面中,您可以找到value列,其中可以包含*或以逗号分隔的元素列表。这意味着它不支持?

因此,只需将您的表达式更改为0 0 5 31 2 *,它将被批准。如果您的功能没有运行,则可以将其禁用。您可以参考本教程:How to disable functions in Azure Functions

更新

由于该函数将计算计时器以获取该函数的运行时间,因此将永远不会出现2/30和2/31,因此它将进行循环计算,并且年份将增加,直到超过限制9999。这种情况下函数将发送异常。

答案 1 :(得分:2)

您不能为每个算法设置永不,但是,周六29日的a年会间隔28年。

0 0 0 2月29日星期六

第一次出现这种情况是2048。

足够好吗?

答案 2 :(得分:1)

计划的WebJob使用的主要格式

  • cron表达式由6个字段组成:{second} {minute} {hour} {day} {month} {week of day}。
  • 支持的运算符为:,-* /
  • 每个字段可以具有特定值(1),范围(1-10),一组 值(1,2,3),所有值(),间隔值(/ 2 == 0,2,4,6,...) 或这些(1,5-10)的混合。
  • 每个值代表一个时间点,例如:“ 5 * * * * *”- 表示每分钟的5秒-> 00:00:05,00:01:05, 00:02:05 ...(不是每5秒一次)。

因此,根据上述规则,您的cron表达式将导致此错误

代替使用def monitor_dumped(): """Returns the files added to dump folder since its last modification time in the form of a dict """ mod_time = os.path.getmtime(folder_to_monitor) # no. of seconds since epoch m = datetime.datetime.fromtimestamp(mod_time) # change time format for difference computation currentDT = datetime.datetime.now() # current system time tslm = currentDT - m # time_since_last_modification need = False before = dict(\[(f, None) for f in os.listdir(folder_to_monitor)\]) if (tslm.seconds > 5): need = True else: print("It hasn't been 5 seconds yet.") while need: time.sleep(10) after = dict(\[(f, None) for f in os.listdir(folder_to_monitor)\]) added = \[f for f in after if not f in before\] if added: print("Added: ", ", ".join(added)) before = after need = False return before ,而使用 0 0 5 31 2 ?

相关问题