http超时,即使在每3分钟(180秒)进行一次服务器调用(ajax调用)以使服务器响应并保持http连接

2024-04-27 16:33:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发目前部署在azure应用服务上的django应用程序。我在docx中生成了报告。格式。在某些情况下,我最多需要5-6分钟。起初我遇到70秒后的活动超时,我用应用程序主机.xdt配置activitytimeout和请求超时。 230秒后,又一次超时。据我所知,这是由于负载均衡器。我知道这是不可配置的应用程序服务。。我尝试过另一种技术,基本上是这样做的,它保持ping后端从客户端后,每180秒。但问题并没有消失。粘贴下面的详细代码。 提前谢谢

   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,一个用于生成报告,另一个用于保持连接活动。但是超时仍然会发生。请帮忙。。。。你知道吗


Tags: reportlogtrue应用程序urldataresponsestatus