Reputation: 3199
I have a request which processes thousands of data. So sometimes It takes more then 5 minutes to complete.
But unfortunately loopback returns timeout(no response from server) before process is completed.
In nodejs request. You can remove request timeout for specific request by below code.
request.setTimeout(0)
Can anyone tell me how can i do this for loopback remote method?
Upvotes: 4
Views: 4085
Reputation: 19622
I am not quite sure of this but you can give it a try as i feel this might work
You can create a interceptor for that particular route or all the routes in the server.js
file.
app.all('/api/*', function(req, res, next){
request.setTimeout(0); // this is the statement and pass it to the next middle ware func.
next();
});
If not you can also use a remote method for that route and add the same there.
Update
If you want it for a single api just use
app.all('<exact api path>', function(req, res, next){
request.setTimeout(0); // this is the statement and pass it to the next middle ware func.
next();
});
Upvotes: 5
Reputation: 3199
It was quite easy then it looked like.
All i had to do is pass http req object
in my remote method and then set timeout to 0.
Visit.remoteMethod(
'caculateDistance',
{
description: 'Calculate distance from beacon using rssi',
accepts: [
{ arg: "req", type: "object", http: { source: "req" } },
{ arg: 'activationId', type: 'string', required: true }
returns: { arg: 'data', type: 'Object', root: true },
http: { verb: 'patch', path: '/:activationId/calculate-distance' },
}
);
Visit.caculateDistance = function (httpReq, activationId, callbackFn) {
httpReq.setTimeout(0);
/////calculations....
});
Thanks anyway!
Upvotes: 8