var geoCorrectionJob = scheduler.scheduleJob('*/30 * * * * *', function(){
//Code section 1
mysqlService.getJoinedMySQLDataWithSuccess().then(function(result) {
// console.log(result) //will log results.
var response, attractionId;
for(var pos = 0; pos < result.length; pos++){
// attractionid = result[pos].attractionid
geolocationController.functionUsingPromise(result[pos]).then(function(response) { // `delay` returns a promise
// console.log(response); // Log the value once it is resolved
attractionId = response[0];
if(response[1] == 1){
attractionsDone.push(attractionId);
if(attractionsDone.length == config.scheduler.UPDATE_SIZE || pos == result.length - 1){
mysqlService.MySQL(attractionsDone).then(function(temp){
attractionsDone = [];
})
.catch((err) => {
console.log(err);
});;
}
}
else if(response[1] == 0){
mysqlService.MySql(attractionId);
}
})
.catch((err) => {
console.log(err);
});
}
})
.catch((err) => {
console.log(err);
});
// Code section 2
mysqlService.getProcessStatusOfAttractions().then(function(status){
// console.log(status);
var processed = status[0].STATUS;
var unprocessed = status[1].STATUS;
var noData = status[2].STATUS;
emailService.sendEmail(processed, noData, unprocessed);
})
.catch((err) => {
console.log(err);
});
});
How do I ensure that "Code section 2" is executed after "Code section 1" is completely executed? Code section 1 has a Promisified task within a for loop. I want Code section 2 to be executed after all the tasks in Code section 1 are completed.