python - 即使每 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,一个用于生成报告,一个用于保持连接。但超时仍然发生。请帮忙....
解决方案
推荐阅读
- node.js - mongoose find() 文档具有大小 > 0 的属性数组
- google-chrome - Zalenium:禁用 chrome 中的下载弹出窗口
- java - 无论如何,您可以按键排序以使用 atStart 和 atEnd for Firebase?
- elasticsearch - Logstash 过滤器从日志消息中复制一些文本
- reactjs - 作为响应策略在材料 ui 的手风琴和选项卡之间切换的最佳方式?
- mysql - SQL 从表中获取矩阵
- python - 从名称列表中随机生成团队
- python - 使用 python 使用 windows 任务调度程序在网络共享上写入文件
- python - 如何根据组对 xml 节点值进行排序?
- javascript - JavaScript 和 Lazarus Pascal 之间的套接字通信