首页 > 解决方案 > 即使每 3 分钟(180 秒)进行一次服务器调用(ajax 调用)以使服务器响应并保持 http 连接处于活动状态,http 也会超时

问题描述

我正在开发当前部署在 azure app service 上的 django 应用程序。我包括在 docx 中生成报告。格式。在某些场景中,我最多需要 5-6 分钟。起初我在 70 秒后遇到了活动超时,我通过使用 applicationHost.xdt 配置活动超时和请求超时解决了这个问题。然后几乎在 230 秒后发生了另一个超时。据我所知,这是由于负载均衡器。我知道它在应用程序服务中是不可配置的。我是否尝试过另一种基本上可以做到的技术是它每 180 秒后不断从客户端 ping 后端。但问题并没有消失。在下面粘贴详细代码。提前致谢

   function pinger(stop)
{
  if (status == true)
  {
    return;
  }
  else
  {
    $.ajax({
    async   : false,  
    url:"{% url 'DummyUrl' %}",
    type: "GET",
    data: {},
    beforeSend:function()
    { 
      console.log('starting dummy')
    },
    success:function(response){
    console.log('success dummy')

    console.log(response.data) 
    },
    complete:function(){},
    error:function (xhr, textStatus, thrownError){}

  });
  return;
  }

}

    function generate_report()
{   
    var status = false; 
    $.ajax({
    async   : true,
    url:"{% url 'GenerateReport' %}",
    headers: { "X-CSRFToken": '{{csrf_token}}' },
    type: "POST",
    data: {},
    beforeSend:function()
    {    
      console.log('starting');
      console.log('readonly');
    },
    success:function(response){
      if (response.data.toString().includes('.docx'))
          {
            console.log(response);
            var url_mask = "{% url 'download report' filename=12345 %}".replace(/12345/, response.data.toString());
            console.log('document generated successfully here is the link');
            status = true;
            show_download_link(url_mask);

          }

      else{ console.log(response)}

      },
    complete:function(){
      console.log('completed')
    },
    error:function (xhr, textStatus, thrownError){
      Error_Link();
      console.log('error+')
    }

  });

         // pinger(stop)
  setTimeout(function(){ pinger(status); }, 180000);
  // setInterval(pinger(stop) , 120000);



}

   $("#generate_report_form").on('submit', function(event){
    event.preventDefault();

   generate_report();

});

上面的代码同时调用了两个 API,一个用于生成报告,一个用于保持连接。但超时仍然发生。请帮忙....

标签: pythondjangoazureazure-web-app-service

解决方案


推荐阅读