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
_______________________________________________
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

Reply via email to