我有一条快速航线,我想开始工作然后返回202。像这样...
const HANDLE_REQUEST = (req, res, next)=>{
LOGGER.log("verbose", "Calling the GET");
setTimeout(()=>{
START_JOB(1, req.query.server, req.query.start, req.query.end);
});
res.status(202).send("Job Started");
next();
};
router.get("/", HANDLE_REQUEST);
这有效,并且202立即发送。
问题是它在大约5分钟后超时...
2019-05-01T09:47:29.074-04:00 [APP/PROC/WEB/0] [ERR] Error: read ECONNRESET
2019-05-01T09:47:29.074-04:00 [APP/PROC/WEB/0] [ERR] at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
我试图像这样设置套接字超时并保持活动状态...
this.server = spdy.createServer(spdyOpts, this.express);
this.server.on("connection", (socket)=>{
socket.setTimeout(this.timeout * 60 * 1000);
socket.setKeepAlive(true, this.timeout * 60 * 1000);
socket.once("timeout", function(){
LOGGER.log("error",`Timed out`);
process.nextTick(socket.destroy);
});
});
this.server.listen(this.port, (err)=>{
if (err){
LOGGER.log("error", err);
return process.exit(1);
}
return LOGGER.log("info", `Server is listening on ${this.port}`);
});
但这似乎无济于事。有没有一种方法可以在Express中启动连接的后台进程(工作人员?)?