Azure计划的WebJob从未完成状态

时间:2017-05-30 23:30:02

标签: azure azure-webjobs azure-servicebus-queues

我有一个每分钟运行一次功能的计划Web作业:

[TimerTrigger("00:01:00", RunOnStartup = true)]

有时会挂起并且在几天内处于“永不完成”状态。这可以防止触发作业的新计划。 Azure日志也没有记录任何条目 - 该运行的日志为空。

我想知道如果作业具有“永不完成”状态/状态,是否有办法告诉Azure调度程序继续进行调度?设置“UseMonitor = true”会这样做吗?

1 个答案:

答案 0 :(得分:1)

据我所知,如果预定的Web作业处理周期性地停留很长时间(或者根本没有完成),那么必须时刻工作功能中的操作需要很长时间或者失败。一切都取决于你的工作在内部实际做了什么。如果它在某些地方变为异步,SDK将继续等待它返回。

据此,我建议您尝试使用webjob的TimeoutAttribute。 如果函数被挂起,很容易根据超时取消函数。它会显示异常。

如果您发现错误太多并且您想要更改,我建议您可以使用ErrorTrigger,您可以参考此article

更多细节,您可以参考以下代码。

我使用队列来测试它,结果和TimerTrigger webjob一样。

  //Change the function timeout value
        [Timeout("00:00:03")]
        public static void  TimeoutJob(
        [QueueTrigger("queue")] string message,
         CancellationToken token,
        TextWriter log)
        {

            Console.WriteLine("From function: Received a message: " + message);

            Task task = new Task(new Action(() =>  /*here is your code*/ Thread.Sleep(5000)), token);
            // this will cancel the task is the token is CancellationRequested and show the exception the task is cancel
            task.Wait();
             Console.WriteLine("From function: Cancelled: Yes");
        }
相关问题