Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions server/app/cronjobs/task-sync/taskSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ function taskSync(){
status:'running'
};
executeTaskSyncForTaskHistory(query,callback);
},
savedTimeSync : function(callback){
addSavedTimePerBots(callback);
}

},function(err,results){
Expand Down Expand Up @@ -157,74 +154,6 @@ function getMinutesDiff(date1,date2){
return Math.abs(Math.round(diff));
}

function getExecutionTime(endTime, startTime) {
var executionTimeInMS = endTime - startTime;
var totalSeconds = Math.floor(executionTimeInMS / 1000);
return totalSeconds;
}

function addSavedTimePerBots(callback) {
var query = {
isDeleted:false
}
botsDao.getAllBots(query,function(err,botList){
if(err){
callback(err,null);
return;
}else if(botList.length > 0){
var count = 0;
for(var i = 0; i<botList.length;i++){
(function(bots){
var query = {
auditType: 'BOTs',
actionStatus: 'success',
isDeleted: false,
auditId: bots.botId
};
auditTrail.getAuditTrails(query, function (err, botAuditTrail) {
if (err) {
logger.error("Error in Fetching Audit Trail.", err);
callback(err, null);
}
if (botAuditTrail.length > 0) {
var totalTimeInSeconds = 0;
for (var m = 0; m < botAuditTrail.length; m++) {
if (botAuditTrail[m].endedOn && botAuditTrail[m].endedOn !== null
&& botAuditTrail[m].auditTrailConfig.manualExecutionTime && botAuditTrail[m].auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(botAuditTrail[m].endedOn, botAuditTrail[m].startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((botAuditTrail[m].auditTrailConfig.manualExecutionTime * 60) - executionTime);
}
}
var totalTimeInMinutes = Math.round(totalTimeInSeconds/60);
var result = {
hours:Math.floor(totalTimeInMinutes / 60),
minutes:totalTimeInMinutes % 60
}
botsDao.updateBotsDetail(bots.botId,{savedTime:result},function(err,data){
if(err){
logger.error(err);
}
count++;
if(count === botList.length){
callback(null,botList);
return;
}
})
} else {
count++;
if(count === botList.length){
callback(null,botList);
return;
}
}
});
})(botList[i]);
}
}else{
logger.debug("There is no BOTs for Saved Time Implementation.");
callback(null,botList);
}
})
}


Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@ CloudFormationBlueprintSchema.methods.launch = function (launchParams, callback)
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData._id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ AWSInstanceBlueprintSchema.methods.launch = function (launchParams, callback) {
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData._id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}
instanceLogModel.createOrUpdate(actionLog._id, instance.id, instanceLog, function (err, logData) {
Expand Down Expand Up @@ -669,6 +675,12 @@ AWSInstanceBlueprintSchema.methods.launch = function (launchParams, callback) {
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData.id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}
instancesDao.updateActionLog(instance.id, actionLog._id, true, timestampEnded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ azureInstanceBlueprintSchema.methods.launch = function(launchParams, callback) {
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData._id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}
instanceLogModel.createOrUpdate(actionLog._id, instance.id, instanceLog, function(err, logData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ openstackInstanceBlueprintSchema.methods.launch = function(launchParams, callbac
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData._id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}
instancesDao.updateActionLog(instance.id, actionLog._id, true, timestampEnded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ vmwareInstanceBlueprintSchema.methods.launch = function(launchParams, callback)
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(launchParams.blueprintData._id,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
});
}
instanceLogModel.createOrUpdate(actionLog._id, instance.id, instanceLog, function(err, logData) {
Expand Down
8 changes: 8 additions & 0 deletions server/app/model/classes/tasks/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ taskSchema.methods.execute = function(userName, baseUrl, choiceParam, appData, b
if (err) {
logger.error("Failed to create or update bots Log: ", err);
}
if(resultTaskExecution.actionStatus === 'success'){
var botService = require('_pr/services/botsService');
botService.updateSavedTimePerBots(taskHistoryData.taskId,function(err,data){
if (err) {
logger.error("Failed to update bots saved Time: ", err);
}
});
}
});
}
self.save();
Expand Down
42 changes: 17 additions & 25 deletions server/app/services/auditTrailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,26 @@ auditTrailService.getBOTsSummary = function getBOTsSummary(queryParam,BOTSchema,
});
},
totalSavedTimeForBots: function(callback){
var query={
auditType:BOTSchema,
actionStatus:'success',
isDeleted:false,
auditId:{$in:auditIds}
};
auditTrail.getAuditTrails(query,function(err,botAuditTrail){
if(err){
callback(err,null);
} else if(botAuditTrail.length > 0){
var totalTimeInSeconds = 0;
for(var j = 0; j < botAuditTrail.length; j++){
if(botAuditTrail[j].endedOn && botAuditTrail[j].endedOn !== null
&& botAuditTrail[j].auditTrailConfig.manualExecutionTime && botAuditTrail[j].auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(botAuditTrail[j].endedOn, botAuditTrail[j].startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((botAuditTrail[j].auditTrailConfig.manualExecutionTime*60) - executionTime);
}
var hours = 0, minutes = 0;
if(botsList.length > 0) {
for (var k = 0; k < botsList.length; k++) {
if(botsList[k].savedTime.hours) {
hours = hours + botsList[k].savedTime.hours;
}
var totalTimeInMinutes = Math.round(totalTimeInSeconds/60);
var result = {
hours:Math.floor(totalTimeInMinutes / 60),
minutes:totalTimeInMinutes % 60
if(botsList[k].savedTime.minutes){
minutes = minutes + botsList[k].savedTime.minutes;
}
callback(null,result);
} else{
callback(null,botAuditTrail.length);
}
});
}
if(minutes >= 60){
hours = hours + Math.floor(minutes / 60);
minutes = minutes % 60;
}
var result = {
hours:hours,
minutes:minutes
}
callback(null,result);
},
totalNoOfFailedBots: function(callback){
var query={
Expand Down
51 changes: 50 additions & 1 deletion server/app/services/botsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var ObjectId = require('mongoose').Types.ObjectId;
var async = require("async");
var apiUtil = require('_pr/lib/utils/apiUtil.js');
var taskService = require('_pr/services/taskService.js');
var tasks = require('_pr/model/classes/tasks/tasks.js');
var auditTrailService = require('_pr/services/auditTrailService.js');
var blueprintService = require('_pr/services/blueprintService.js');
var auditTrail = require('_pr/model/audit-trail/audit-trail.js');
Expand Down Expand Up @@ -130,6 +129,7 @@ botsService.updateBotsScheduler = function updateBotsScheduler(botId,botObj,call
}
});
if (botsData[0].botLinkedCategory === 'Task') {
var tasks = require('_pr/model/classes/tasks/tasks.js');
tasks.getTaskById(botId, function (err, task) {
if (err) {
logger.error("Error in fetching Task details", err);
Expand Down Expand Up @@ -303,6 +303,48 @@ botsService.getBotsHistory = function getBotsHistory(botId,botsQuery,callback){
});
}

botsService.updateSavedTimePerBots = function updateSavedTimePerBots(botId,callback){
var query = {
auditType: 'BOTs',
actionStatus: 'success',
isDeleted: false,
auditId: botId
};
auditTrail.getAuditTrails(query, function (err, botAuditTrail) {
if (err) {
logger.error("Error in Fetching Audit Trail.", err);
callback(err, null);
}
if (botAuditTrail.length > 0) {
var totalTimeInSeconds = 0;
for (var m = 0; m < botAuditTrail.length; m++) {
if (botAuditTrail[m].endedOn && botAuditTrail[m].endedOn !== null
&& botAuditTrail[m].auditTrailConfig.manualExecutionTime && botAuditTrail[m].auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(botAuditTrail[m].endedOn, botAuditTrail[m].startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((botAuditTrail[m].auditTrailConfig.manualExecutionTime * 60) - executionTime);
}
}
var totalTimeInMinutes = Math.round(totalTimeInSeconds / 60);
var result = {
hours: Math.floor(totalTimeInMinutes / 60),
minutes: totalTimeInMinutes % 60
}
bots.updateBotsDetail(botId, {savedTime: result}, function (err, data) {
if (err) {
logger.error(err);
callback(err, null);
return;
}
callback(null, data);
return;
})
} else {
callback(null, botAuditTrail);
return;
}
});
}

botsService.getPerticularBotsHistory = function getPerticularBotsHistory(botId,historyId,callback){
async.waterfall([
function(next){
Expand Down Expand Up @@ -366,6 +408,7 @@ botsService.executeBots = function executeBots(botId,reqBody,callback){
var taskObj = {
'taskConfig.scriptDetails':encryptedParamList
}
var tasks = require('_pr/model/classes/tasks/tasks.js');
tasks.updateTaskDetail(botId,taskObj,callback);
}
}, function (err, data) {
Expand Down Expand Up @@ -547,6 +590,12 @@ function encryptedParam(paramDetails, callback) {
return;
}

function getExecutionTime(endTime, startTime) {
var executionTimeInMS = endTime - startTime;
var totalSeconds = Math.floor(executionTimeInMS / 1000);
return totalSeconds;
}




Expand Down