Skip to content

Instantly share code, notes, and snippets.

@attdona
Last active February 17, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attdona/dc5018d9586e8c73d1d15c1040c9cc44 to your computer and use it in GitHub Desktop.
Save attdona/dc5018d9586e8c73d1d15c1040c9cc44 to your computer and use it in GitHub Desktop.
let async = require('async')
function downloadSentinel(promObj) {
return new Promise((resolve, reject) => {
function makeRequest(url, i, callback) {
var sys = require('util'),
exec = require('child_process').exec,
child;
var directory = __dirname.substring(0, __dirname.indexOf("\\app_api"));
console.log("executing:", directory + '\\downloadProducts.sh ' + promObj.ID[i] + ' ' + promObj.Name[i]);
child = exec(directory + '\\downloadProducts.sh ' + promObj.ID[i] + ' ' + promObj.Name[i]);
child.on("error", function (error) {
console.log("child error:", error);
callback(error);
})
child.stdout.on('data', function (data) {
console.log(data.toString());
callback();
});
child.on('exit', function (exit) {
console.log("child exit:", exit);
callback(exit);
})
}
async.eachOfLimit(promObj.requestURLS, 2, makeRequest, function (err) {
if (err) reject(promObj)
else {
resolve(promObj);
}
});
});
}
let promObj = {
requestURLS: ['url1', 'url2', 'url3'],
ID: [1, 2, 3],
Name: ["n1", "n2", "n3"]
}
downloadSentinel(promObj).then((res) => {
console.log("THEN:", res)
}).catch((err) => {
console.log("CATCH:", err) // err is the shell script exit code or shell stderr
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment