dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39100
Re: Node.js Question for Updating Sharing Settings
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 <hardingt@xxxxxxxxx> 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: hardingt@xxxxxxxxx
> <javascript:_e(%7B%7D,'cvml','hardingt@xxxxxxxxx');>
> +1 (541) 632-6623
>
--
Pierre Dane
Development Manager
Jembi Health Systems
Follow ups
References