计划的 Azure Web 作业超时

时间:2021-06-24 12:35:42

标签: azure timer azure-webjobs azure-webjobs-triggered

我试图让 Azure 网络作业每小时运行一次,但要么文档非常混乱,要么我遗漏了一些东西。我正在使用带有以下签名的 TimerTrigger

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 窗格中,schedule 列的值为 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 的目的)?

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

对于每小时运行一次方法的要求,您可以使用 azure 函数 timertrigger 代替 webjob。

您可以参考this document如何创建函数应用,然后在函数应用中创建定时器触发器。指定定时器触发器的cron表达式时,请用0 0 * * * *设置。然后它会每小时触发一次。