Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopback timeout(no response from server) when make a time consume request

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?

like image 700
Ankur Akvaliya Avatar asked Dec 13 '22 19:12

Ankur Akvaliya


1 Answers

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!

like image 139
Ankur Akvaliya Avatar answered Dec 18 '22 00:12

Ankur Akvaliya