1

i get an ETIMEDOUT error after a few successful calls... Here is the Code:

soap.createClient("./WSDL/test.wsdl", function (err, soapClient)
{
    if (err)
    {
         throw new Error(err)
    };

    bpData.forEach(function (elementOfArray)
    {
        soapClient.service.binding.Update({
             ProductUpload: {
                 ID: elementOfArray.ProductID,
                 newIndicator: 'false',
                 UpdateIndicator: 'true',
                 UpdateDate: dateFormat(new Date(), 'yyydd'),
                 RawData: elementOfArray.RawData1,
                 RawData2: elementOfArray.RawData2
             }
         }, function (err, result)
         {
               if (err)
               {
                   console.log(err);
                   //throw new Error(err);
                } else
                {
                    console.log(JSON.stringify(result));
                    return JSON.stringify(result);
                 }
            }
        );
.....

I already tried to set the timeout parameter up but nothing changed...

Thanks!

  • Maybe you're querying to fast and some spam protection kicks in. Have you tried throttling you requests? – Sirko Apr 18 '17 at 13:44
  • @Sirko how can I throttle the request? Thanks! – Christoph Grimm Apr 18 '17 at 20:20
  • I'm sure there are libraries for this, but the basic principle would be as follows: take the first item from your array and perform the request. when it has finished, take the second item and repeat the process. do this up until you processed all the items from the array. maybe between two request you'll have to add some delay using `setTimeout()`. – Sirko Apr 18 '17 at 20:25

2 Answers2

1

thanks guys! It works making it now with a async queue :)! Have a good evening

0

forEach is a sync function but soapClient.service.binding.Update is async meaning that you queue all requests in an instant. You should use async.js or create your own function to wait for the first request to finish to go to the second one.

itsundefined
  • 1,409
  • 2
  • 12
  • 32
  • tried it `async.each(bpFormattedData, function (elementOfArray)` but same happens. I think as @Sirko says I must throttle it but unfortunately i dont know how. – Christoph Grimm Apr 18 '17 at 20:22
  • http://stackoverflow.com/a/30514817/7868639 This is exactly what you are looking for :) – itsundefined Apr 18 '17 at 20:24