首页 > 解决方案 > 计划的 Azure Web 作业超时

问题描述

我试图让 Azure webjob 每小时运行一次,但是文档非常混乱,或者我遗漏了一些东西。我正在使用TimerTrigger具有以下签名的 a:

public void RunHourly([TimerTrigger("0 * * * *")] TimerInfo myTimer)

并将其部署在 Azure 中。当我在 Azure 中运行 webjob 时,在输出中我看到:

[06/24/2021 11:35:32 > 886219: INFO] info: Host.Triggers.Timer[5]
[06/24/2021 11:35:32 > 886219: INFO]       The next 5 occurrences of the 'RunHourly' schedule (Cron: '0 * * * *') will be:
[06/24/2021 11:35:32 > 886219: INFO]       06/24/2021 12:00:00Z
[06/24/2021 11:35:32 > 886219: INFO]       06/24/2021 13:00:00Z
[06/24/2021 11:35:32 > 886219: INFO]       06/24/2021 14:00:00Z
[06/24/2021 11:35:32 > 886219: INFO]       06/24/2021 15:00:00Z
[06/24/2021 11:35:32 > 886219: INFO]       06/24/2021 16:00:00Z

所以一切看起来都很好。在 azure 门户的 webjob 窗格中,计划列的值为 n/a,因为我没有在 settings.job 中提供计划,当我手动启动 webjob 时,几分钟后出现以下错误

[06/24/2021 11:41:34 > 886219: ERR ] Command 'cmd /c ""run.exe""' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
cmd /c ""run.exe""
[06/24/2021 11:41:35 > 886219: SYS INFO] Status changed to Failed
[06/24/2021 11:41:35 > 886219: SYS ERR ] System.AggregateException: One or more errors occurred. ---> Kudu.Core.Infrastructure.CommandLineException: Command 'cmd /c ""run.exe""' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.

所以我的问题是我应该如何使用 TimerTrigger 让一个方法每小时或每天运行一次?我是否也需要有一个时间表(有点违背 TimerTrigger 的目的)?

任何帮助表示赞赏

标签: azuretimerazure-webjobsazure-webjobs-triggered

解决方案


对于每小时运行一个方法的要求,您可以使用 azure 函数 timertrigger 而不是 webjob。

您可以参考此文档了解如何创建函数应用,然后在函数应用中创建计时器触发器。指定定时器触发器的 cron 表达式时,请用0 0 * * * *. 然后每隔一小时触发一次。


推荐阅读