简体   繁体   English

由于长时间运行的SQL过程,Angular的POST而导致Nodejs错误

[英]Nodejs error due to long running SQL Procedure, POST from Angular

On my site I currently use Angular / NodeJs/ and a SQL database. 我目前在我的网站上使用Angular / NodeJs /和一个SQL数据库。 On the site I make a lot of calls from the site to NodeJs to the database and it works fine. 在该站点上,我从该站点向NodeJs到数据库进行了很多调用,并且工作正常。 However, when I run a stored procedure that takes a long time to process I get back the following in the console: 但是,当我运行需要很长时间才能处理的存储过程时,会在控制台中返回以下内容:

POST /job_bbb - - ms - - POST / job_bbb--ms--

From what I have seen on Google this is due to no response being sent back. 从我在Google上看到的情况来看,这是由于没有回复发送回。

Any ideas on how to remedy this? 关于如何解决这个问题的任何想法? Any help would be greatly appreciated. 任何帮助将不胜感激。

Angular call to my service: 角度呼叫我的服务:

this.teradataService.getBBB(this.id).subscribe(bbbresults => this.bbbresults = bbbresults,
        error => console.log('ERROR!'),
        () => {
 });

Service HTTP POST: 服务HTTP POST:

  getBBB(id): Observable<[BBBResult]> { const url = 'http://localhost:3000/job_bbb'; const data = ({ id: id }); return this._http.post(url, data) .pipe( map((res) => { console.log(res); return <[BBBResult]> res; }) ); } 

Nodejs Nodejs的

 router.post('/job_bbb', function (req, res) { var id = req.body.id; var sql = "CALL Stored Proecedure Here;"; console.log(sql); return database.read(sql) .then((x) => { console.log(x) res.send(x); }) }); 

You might try increasing the server timeout for the server response. 您可能会尝试增加服务器响应的服务器超时时间。 If the node server is Express: 如果节点服务器为Express:

 server.setTimeout(msecs);

Or probably better: 也许更好:

router.post('/job_bbb', function (req, res) {
       req.setTimeout(msecs);
       ....
});

The default timeout should be 2 minutes. 默认超时应为2分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM