Thanks Pierre, Not sure how I would set up the recursive loop in javascript, I had heard about async from stack overflow as well, I was thinking of trying that, but I kind of like how quickly this works, not needing to wait for the response from one request before sending the next. The DHIS2 hardware I am working with just doesn't seem to keep up after a certain number of requests however, hence my attempt to slow them down.
Timothy Harding RPCV Vanuatu Skype: hardi...@gmail.com +1 (541) 632-6623 On Mon, Aug 24, 2015 at 9:39 AM, Pierre Dane <pie...@jembi.org> wrote: > might be best to try a recursive loop using setInterval or setTimeout with > a configurable value (I.e. a method calling itself) . or you could look at > the async library to make things synchronous . > > > On Monday, August 24, 2015, Timothy Harding <hardi...@gmail.com> wrote: > >> Hello DHIS2 Devs, >> >> I've got a script that works pretty well for updating a bunch of sharing >> settings for various objects using node.js. The only problem is, I am >> getting timeouts when the object update counts get too high (500+). >> >> I am a bit new to the asynchronous nature of node.js, and I like that I >> can bundle a lot of updates into one without needing to worry that I need a >> response for one before sending the request for the next. The downside is, >> I have no idea where to put the sleep timer to slow down the volume of >> requests. Everywhere I've put it so far increases the timeouts, rather than >> decreases them. I know there are some node.js experts out there on the >> DHIS2 dev list so, perhaps someone has run into something similar: >> >> var serverConfigPOST = serverConfig; >> serverConfigPOST.dhis2server.method = "POST"; >> var i=0; >> for(i=0; i < dataElementsToUpdate.length; i++){ >> >> Tried here >> var postData = JSON.stringify(dataElementsToUpdate[i]); >> serverConfigPOST.dhis2server.path = >> "/dhis/api/sharing?type=dataElement&id=" + dataElementsToUpdate[i]. >> object.id; >> serverConfigPOST.dhis2server.headers = { >> 'Content-Type': 'application/json', >> 'Content-Length': postData.length >> }; >> console.log(serverConfigPOST); >> var req = https.request(serverConfigPOST.dhis2server, function(res) { >> console.log('STATUS: ' + res.statusCode); >> console.log('HEADERS: ' + JSON.stringify(res.headers)); >> res.setEncoding('utf8'); >> res.on('data', function (chunk) { >> console.log('BODY: ' + chunk); >> }); >> }); >> req.on('error', function(e) { >> //console.log('problem with request: ' + e.message); >> }); >> // write data to request body >> req.write(postData); >> req.end(); >> >> Tried here >> // if(i==20){ >> // break; >> // } >> } >> >> Not quite sure how to slow this one down, I may just have to run/rerun it >> with different starting and stopping i values in the mean time. >> >> Timothy Harding >> RPCV Vanuatu >> Skype: hardi...@gmail.com >> +1 (541) 632-6623 >> > > > -- > Pierre Dane > > Development Manager > Jembi Health Systems > >
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp