为什么我的 Trigger Azure WebJob 被多次触发

Why is my Triggered AzureWebJob being triggered multiple times

我看到 this SO question and I am getting a similar, but different effect. I have used the information from Scheduling Azure WebJobs with cron expressions 并查看触发的 WebJob api 我得到:

  1. 整点触发,latest_run.triggered 设置为 "External - "。
  2. 多个 (> 10) 运行 在 10 点过后,latest_run.triggered 设置为 "Schedule - * 10 * * * *"。

日志显示 运行 多次(比如 19 次!)当 运行 在整点 10 点时。这是 job_scheduler.log 文件末尾的片段(我已将其缩短。WebJob 的最后两次调用 运行 分别为 16 次和 19 次)。

[03/10/2016 10:10:52 > bdda8b: SYS INFO] WebJob invoked
[03/10/2016 10:10:52 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.2973642
[03/10/2016 10:10:53 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.5786066
[03/10/2016 10:10:54 > bdda8b: SYS INFO] WebJob invoked
[03/10/2016 10:10:54 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.4536019
[03/10/2016 10:10:55 > bdda8b: SYS INFO] WebJob invoked
[03/10/2016 10:10:55 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.4067190
[03/10/2016 10:10:56 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.7034940
[03/10/2016 10:10:57 > bdda8b: SYS INFO] WebJob invoked
[03/10/2016 10:10:57 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.5629458
[03/10/2016 10:10:58 > bdda8b: SYS INFO] Next schedule expected in 00:00:00.0187612
[03/10/2016 10:11:00 > bdda8b: SYS INFO] WebJob invoked
[03/10/2016 10:11:00 > bdda8b: SYS INFO] Next schedule expected in 00:59:00.9405909
[03/10/2016 10:27:57 > bdda8b: SYS INFO] Scheduling WebJob with * 10 * * * * next schedule expected in 00:42:03.7574703

注意:job_scheduler 文件不显示 运行 在 0 点 运行。然而,Azure WebJob Scheduler 说它 运行 当时的工作。

如果我在 Azure 门户中手动触发 WebJob,那么它只会 运行 一次(根据 Azure WebJob 仪表板),所以调度程序似乎在做一些有趣的事情。

我的 WebJob 是 Web 服务的一部分,并使用发布与网站一起部署。我有一个触发式 WebJob,设计为每小时 运行 一次。我的 WebJob setting.job 文件如下所示:

{
   //This will run every hour at 10 minutes past the hour
   "schedule": "* 10 0-23 * * *"
}

我的 webjob-publish-settings.json 文件(我相信它不再被使用)看起来像这样:

{
 "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
 "webJobName": "PrintProcessorWebJob",
 "startTime": "2014-06-23T00:00:00+08:00",
 "endTime": "2020-01-01T00:00:00+01:00",
 "jobRecurrenceFrequency": "Hour",
 "interval": 1,
 "runMode": "Scheduled"
}

认为这是一个新问题,但在尝试对其进行诊断时,我删除了现有的 WebJob,因此我丢失了旧日志。我知道 WebJobs 的规则在开发过程中发生了变化,也许我没有正确更新。

主要问题是您的 cron 表达式不正确。 * 10 * * * * 表示 "Run every second for one minute at 10 minutes past the hour"。相反,你想要 0 10 * * * *.

第二个问题是您似乎有 Azure 调度程序的残余,您需要摆脱这些残余。尝试转到调度程序下的 Azure 门户,并删除任何不应该存在的内容。你的 webjob-publish-settings.json 应该看起来像 this.