Azure WebJob命令超时

本文关键字:超时 命令 WebJob Azure | 更新日期: 2023-09-27 18:19:18

Azure Web Jobs出现问题。我们创建了一个c#控制台应用程序,将其压缩,并创建了新的Web Job。这是一个c#控制台应用程序,它将不断地访问我们的一个web服务来处理队列中的项目。

每当我们运行Web Job时,我们都会得到以下错误:

'cmd/c xxxxxxxx.... .由于没有输出和CPU活动而中止121秒。您可以将SCM_COMMAND_IDLE_TIMEOUT设置为解决问题

当我们将SCM_COMMAND_IDLE_TIMEOUT增加到600(10分钟)时。作业DOES运行了10分钟——然后我们得到了同样的错误,同样的121 seconds错误。

我们做错了什么?

以下是控制台应用程序代码:
static void Main(string[] args)
    {
        bool ThereAreItemsInQueue = true;
        int Counter = 1;
        DateTime StartTime = DateTime.Now;
        while(ThereAreItemsInQueue)
        {
            Task.Run(() => {
                try
                {
                    //DEQUEUE
                    byte[] response = HttpHelper.HttpPOST(@"xxxxxxxxxxxxx", new byte[0]);
                    string strResponse = System.Text.Encoding.Default.GetString(response);
                    System.Diagnostics.Trace.TraceError("Attempt #" + Counter + "DEQUEUE FINISHED. Response:" + strResponse);
                    //CHECK IF THE QUEUE IS EMPTY
                    if (strResponse.Contains("Were Done"))
                        ThereAreItemsInQueue = false;
                }
                catch(Exception ex)
                {
                    System.Diagnostics.Trace.TraceError("Error Has Occured on attempt #" + Counter + "." + ex.Message + "'r" + ex.StackTrace);
                }
            });
            System.Threading.Thread.Sleep(5000);
            //SEE IF THIS HAS BEEN RUNNING FOR MORE THAN 24 HOURS
            if (DateTime.Now.Subtract(StartTime).TotalHours >= 24)
                ThereAreItemsInQueue = false;
            Counter++;
        }
    }

我们处理这个问题的方法是否错误?

注意:每个HttpHelper.HttpPOST请求大约需要2秒-所以这不是问题。

注2:我们使用Task.Run创建"设置并忘记它"类型的请求。

注3:"始终在线"的网站设置是打开的。

Azure WebJob命令超时

对于触发的WebJobs,增加空闲超时的方法是使用应用程序设置:WEBJOBS_IDLE_TIMEOUT。设置为您想要的超时时间,以秒为单位。

该错误令人困惑,仅指部署期间的空闲超时。

https://github.com/projectkudu/kudu/wiki/Web-jobs配置设置

这似乎解决了我的问题:

if (Counter % 25 == 0)
   Console.WriteLine("Heartbeat");

我猜你必须不断地向控制台输出以保持作业运行。