Example #1
0
 bots.getBotsById(task._id,function(err,data){
     if(err){
         logger.error(err);
     }else if(data.length > 0){
         var currentDate = new Date().getTime();
         if(((data[0].isBotScheduled === false || (data[0].botScheduler.cronEndOn && currentDate >= data[0].botScheduler.cronEndOn)) ||
             (data[0].isBotScheduled === true && data[0].botScheduler.cronEndOn && currentDate >= data[0].botScheduler.cronEndOn) ||
             (task.isTaskScheduled === true && task.taskScheduler.cronEndOn && currentDate >= task.taskScheduler.cronEndOn)) && user === 'system'){
             crontab.cancelJob(data[0].cronJobId);
             bots.updateBotsScheduler(data[0]._id,function(err, updatedData) {
                 if (err) {
                     logger.error("Failed to update Bots Scheduler: ", err);
                     callback(err,null);
                     return;
                 }
                 logger.debug("Scheduler is ended on for Bots. "+data[0].botName);
                 callback(null,updatedData);
                 return;
             });
             crontab.cancelJob(task.cronJobId);
             taskDao.updateTaskScheduler(task._id,function(err, updatedData) {
                 if (err) {
                     logger.error("Failed to update Task Scheduler: ", err);
                     callback(err,null);
                     return;
                 }
                 logger.debug("Scheduler is ended on for Task. "+task.name);
                 callback(null,updatedData);
                 return;
             });
         }else {
             var botExecutionCount = data[0].executionCount + 1;
             taskDao.updateTaskExecutionCount(task._id,taskExecutionCount,function(err,data){
                 if(err){
                     logger.error("Error while updating Task Execution Count");
                 }
             });
             var botUpdateObj = {
                 executionCount:botExecutionCount,
                 lastRunTime:new Date().getTime()
             }
             bots.updateBotsDetail(task._id, botUpdateObj, function (err, data) {
                 if (err) {
                     logger.error("Error while updating Bot Execution Count");
                 }
             });
         }
     }else{
         logger.debug("There is no BOTs data present in DB");
     }
 });
Example #2
0
 (function(task) {
     if(task.cronJobId && task.cronJobId !== null){
         cronTab.cancelJob(task.cronJobId);
     }
     if(serialTaskList.length ===0) {
         serialTaskList.push(function (next) {schedulerService.executeSerialScheduledTasks(task, next);
         });
     }else{
         serialTaskList.push(function (cronJobId,next) {
             cronTab.cancelJob(cronJobId);
             schedulerService.executeSerialScheduledTasks(task, next);
         });
     }
     if(serialTaskList.length === tasks.length){
         if(serialTaskList.length > 0) {
             async.waterfall(serialTaskList, function (err, data) {
                 if (err) {
                     logger.error(err);
                     return;
                 }
                 cronTab.cancelJob(data);
                 logger.debug("Serial Task Scheduler Completed");
                 var catalystScheduler = require('_pr/cronjobs/catalyst-scheduler/catalystScheduler.js');
                 catalystScheduler.executeSerialScheduledTasks();
                 return;
             })
         }else{
             logger.debug("There is no Serial scheduled Task right now.");
             return;
         }
     }
 })(tasks[i]);
// Cancel job and remove it from the map
function removeCrontabJob(key) {
  if (global.jobsMap[key]) {
    crontab.cancelJob(global.jobsMap[key]);
    global.jobsMap[key] = null;
    console.log("Current Crontab Jobs: ", global.jobsMap);
  }
};
Example #4
0
 async.waterfall(serialTaskList, function (err, data) {
     if (err) {
         logger.error(err);
         return;
     }
     cronTab.cancelJob(data);
     logger.debug("Serial Task Scheduler Completed");
     var catalystScheduler = require('_pr/cronjobs/catalyst-scheduler/catalystScheduler.js');
     catalystScheduler.executeSerialScheduledTasks();
     return;
 })
Example #5
0
 tasks.getTaskById(botId, function (err, task) {
     if (err) {
         logger.error("Error in fetching Task details", err);
     } else if (task.isTaskScheduled === true) {
         tasks.updateTaskScheduler(botId, function (err, updateData) {
             if (err) {
                 logger.error("Error in Updating Task details", err);
             }
         });
         if (task.cronJobId && task.cronJobId !== null) {
             var cronTab = require('node-crontab');
             cronTab.cancelJob(task.cronJobId);
         }
     }
 });
Example #6
0
 Tasks.updateTaskById(req.params.taskId, taskData, function(err, updateCount) {
     if (err) {
         logger.error(err);
         res.status(500).send(errorResponses.db.error);
         return;
     }
     if (updateCount) {
         if(taskData.isTaskScheduled === true){
             if(taskData.executionOrder === 'PARALLEL'){
                 catalystSync.executeParallelScheduledTasks();
             }else{
                 catalystSync.executeSerialScheduledTasks();
             }
         }else if(scriptTask.cronJobId && scriptTask.cronJobId !== null){
             cronTab.cancelJob(scriptTask.cronJobId);
         }else{
             logger.debug("There is no cron job associated with Task ");
         }
         if(taskData.serviceDeliveryCheck === true) {
             Tasks.getTaskById(req.params.taskId, function (err, task) {
                 if (err) {
                     logger.error(err);
                 } else {
                     botsService.createOrUpdateBots(task, 'Task', task.taskType, function (err, data) {
                         if (err) {
                             logger.error("Error in creating bots entry." + err);
                         }
                     });
                 }
             });
         }else{
             botsService.removeSoftBotsById(req.params.taskId, function (err, data) {
                 if (err) {
                     logger.error("Error in updating bots entry." + err);
                 }
             });
         }
         res.send({
             updateCount: updateCount
         });
     } else {
         res.send(400);
     }
 });
Example #7
0
schedulerService.executeScheduledBots = function executeScheduledBots(bots,callback) {
    logger.debug("Bots Scheduler is started for - "+bots.botName);
    var currentDate = new Date().getTime();
    if(currentDate >= bots.botScheduler.cronEndOn){
        crontab.cancelJob(bots.cronJobId);
        botsDao.updateBotsScheduler(bots._id,function(err, updatedData) {
            if (err) {
                logger.error("Failed to update Bots Scheduler: ", err);
                callback(err,null);
                return;
            }
            logger.debug("Scheduler is ended on for Bots. "+bots.botName);
            callback(null,updatedData);
            return;
        });
    }else{
        var cronJobId = cronTab.scheduleJob(bots.botScheduler.cronPattern, function () {
            botsDao.updateCronJobIdByBotId(bots._id,cronJobId,function(err,data){
                if(err){
                    logger.error("Error in updating cron job Ids. "+err);
                }
            })
            if(bots.botLinkedCategory === 'Blueprint') {
                botsService.executeBots(bots.botId, bots.runTimeParams, function (err, historyData) {
                    if (err) {
                        logger.error("Failed to execute Bots.", err);
                        return;
                    }
                    logger.debug("Bots Execution Success for - ", bots.botName);
                    return;
                });
            }else{
                botsService.executeBots(bots.botId,null,function (err, historyData) {
                    if (err) {
                        logger.error("Failed to execute Bots.", err);
                        return;
                    }
                    logger.debug("Bots Execution Success for - ", bots.botName);
                    return;
                });
            }
        });
    }
}
Example #8
0
 (function(task) {
     if(task.cronJobId && task.cronJobId !== null){
         cronTab.cancelJob(task.cronJobId);
     }
     parallelTaskList.push(function(callback){schedulerService.executeParallelScheduledTasks(task,callback);});
     if(parallelTaskList.length === tasks.length){
         if(parallelTaskList.length > 0) {
             async.parallel(parallelTaskList, function (err, results) {
                 if (err) {
                     logger.error(err);
                     return;
                 }
                 logger.debug("Task Scheduler Completed for Parallel");
                 return;
             })
         }else{
             logger.debug("There is no Parallel scheduled Task right now.");
             return;
         }
     }
 })(tasks[i]);
Example #9
0
 (function(bot) {
     if(bot.cronJobId && bot.cronJobId !== null){
         cronTab.cancelJob(bot.cronJobId);
     }
     botsList.push(function(callback){schedulerService.executeNewScheduledBots(bot,callback);});
     if(botsList.length === bots.length){
         if(botsList.length > 0) {
             async.parallel(botsList, function (err, results) {
                 if (err) {
                     logger.error(err);
                     return;
                 }
                 logger.debug("New Bots Scheduler Completed");
                 return;
             })
         }else{
             logger.debug("There is no scheduled New Bots right now.");
             return;
         }
     }
 })(bots[i]);
Example #10
0
schedulerService.executeSerialScheduledTasks = function executeSerialScheduledTasks(task,callback) {
    logger.debug("Task Scheduler is started for Serial Task. "+task.name);
    var currentDate = new Date().getTime();
    if(currentDate >= task.taskScheduler.cronEndOn){
        crontab.cancelJob(task.cronJobId);
        taskDao.updateTaskScheduler(task._id,function(err, updatedData) {
            if (err) {
                logger.error("Failed to update Task Scheduler: ", err);
                callback(err,null);
                return;
            }
            logger.debug("Scheduler is ended on for Task. "+task.name);
            callback(null,updatedData);
            return;
        });
    }else{
        var cronJobId = cronTab.scheduleJob(task.taskScheduler.cronPattern, function () {
            taskDao.updateCronJobIdByTaskId(task._id,cronJobId,function(err,data){
                if(err){
                    logger.error("Error in updating cron job Ids. "+err);
                }
            })
            taskService.executeTask(task._id, "system", "undefined", "undefined", "undefined","undefined","undefined",function(err, historyData) {
                if (err === 404) {
                    logger.error("Task not found.", err);
                    callback(err,null);
                    return;
                } else if (err) {
                    logger.error("Failed to execute task.", err);
                    callback(err,null);
                    return;
                }
                logger.debug("Task Execution Success: ", task.name);
                callback(null,cronJobId);
                return;
            });
        });
    }
}
Example #11
0
 Tasks.getTaskById(req.params.taskId, function (err, task) {
     if (err) {
         logger.error(err);
     }
     if (task.isTaskScheduled === true) {
         if (taskData.executionOrder === 'PARALLEL') {
             catalystSync.executeParallelScheduledTasks();
         } else {
             catalystSync.executeSerialScheduledTasks();
         }
     }else if(task.cronJobId && task.cronJobId !== null){
         cronTab.cancelJob(task.cronJobId);
     }else{
         logger.debug("There is no cron job associated with Task ");
     }
     if (task.serviceDeliveryCheck === true) {
         botsService.createOrUpdateBots(task, 'Task', task.taskType, function (err, data) {
             if (err) {
                 logger.error("Error in creating bots entry." + err);
             }
         });
     }
 })
Example #12
0
HttpReceiver.prototype._stopReceiver = function () {
  if (this._cronObj) { 
      cron.cancelJob(this._cronObj);
      this._cronObj = null;
      this._receiverStarted = false;
    }
    
    if (this._intervalObj) { 
      clearInterval(this._intervalObj); 
      this._intervalObj = null;
      this._receiverStarted = false;
    }
    
    if (this._timeoutObj) { 
      clearTimeout(this._timeoutObj); 
      this._timeoutObj = null;
      this._receiverStarted = false;
    }
    
    if (this._opts.manualPolling) {
        this._receiverStarted = false;
    }
};
Example #13
0
    taskDao.getTaskById(taskId, function(err, task) {
        if (err) {
            var error = new Error('Failed to fetch Task.');
            error.status = 500;
            return callback(error, null);
        }
        if (task) {
            if (task.taskType.CHEF_TASK) {
                paramOptions = paramOptions.attributes;
            } else if (task.taskType.SCRIPT_TASK) {
                paramOptions = paramOptions.scriptDetails;
            }
            var blueprintIds = [];
            if (task.blueprintIds && task.blueprintIds.length) {
                blueprintIds = task.blueprintIds;
            }
            task.botParams = paramOptions;
            task.botTagServer = botTagServer;
            var auditTrailId = null;
            var taskExecutionCount = 0;
            if(task.executionCount){
                taskExecutionCount = task.executionCount + 1
            }else{
                taskExecutionCount = 1;
            }
            if(task.serviceDeliveryCheck === true){
                var actionObj={
                    auditType:'BOTs',
                    auditCategory:'Task',
                    status:'running',
                    action:'BOTs Task Execution',
                    actionStatus:'running',
                    catUser:user
                };
                var auditTrailObj = {
                    nodeIds:task.taskConfig.nodeIds,
                    name:task.name,
                    type:task.botType,
                    description:task.shortDesc,
                    category:task.botCategory,
                    executionType:task.taskType,
                    manualExecutionTime:task.manualExecutionTime,
                    nodeIdsWithActionLog:[]
                };
                bots.getBotsById(task._id,function(err,data){
                    if(err){
                        logger.error(err);
                    }else if(data.length > 0){
                        var currentDate = new Date().getTime();
                        if(((data[0].isBotScheduled === false || (data[0].botScheduler.cronEndOn && currentDate >= data[0].botScheduler.cronEndOn)) ||
                            (data[0].isBotScheduled === true && data[0].botScheduler.cronEndOn && currentDate >= data[0].botScheduler.cronEndOn) ||
                            (task.isTaskScheduled === true && task.taskScheduler.cronEndOn && currentDate >= task.taskScheduler.cronEndOn)) && user === 'system'){
                            crontab.cancelJob(data[0].cronJobId);
                            bots.updateBotsScheduler(data[0]._id,function(err, updatedData) {
                                if (err) {
                                    logger.error("Failed to update Bots Scheduler: ", err);
                                    callback(err,null);
                                    return;
                                }
                                logger.debug("Scheduler is ended on for Bots. "+data[0].botName);
                                callback(null,updatedData);
                                return;
                            });
                            crontab.cancelJob(task.cronJobId);
                            taskDao.updateTaskScheduler(task._id,function(err, updatedData) {
                                if (err) {
                                    logger.error("Failed to update Task Scheduler: ", err);
                                    callback(err,null);
                                    return;
                                }
                                logger.debug("Scheduler is ended on for Task. "+task.name);
                                callback(null,updatedData);
                                return;
                            });
                        }else {
                            var botExecutionCount = data[0].executionCount + 1;
                            taskDao.updateTaskExecutionCount(task._id,taskExecutionCount,function(err,data){
                                if(err){
                                    logger.error("Error while updating Task Execution Count");
                                }
                            });
                            var botUpdateObj = {
                                executionCount:botExecutionCount,
                                lastRunTime:new Date().getTime()
                            }
                            bots.updateBotsDetail(task._id, botUpdateObj, function (err, data) {
                                if (err) {
                                    logger.error("Error while updating Bot Execution Count");
                                }
                            });
                        }
                    }else{
                        logger.debug("There is no BOTs data present in DB");
                    }
                });
                auditTrailService.insertAuditTrail(task,auditTrailObj,actionObj,function(err,data) {
                    if (err) {
                        logger.error(err);
                    }
                    auditTrailId = data._id;
                    task.execute(user, hostProtocol, choiceParam, appData, blueprintIds, task.envId, auditTrailId, function (err, taskRes, historyData) {
                        if (err) {
                            var error = new Error('Failed to execute task.');
                            error.status = 500;
                            return callback(error, null);
                        }
                        if (historyData) {
                            taskRes.historyId = historyData.id;
                        }
                        auditTrailService.updateAuditTrail('BOTs',auditTrailId,{auditHistoryId:historyData.id},function(err,auditTrail){
                            if (err) {
                                logger.error("Failed to create or update bots Log: ", err);
                            }
                        });
                        callback(null, taskRes);
                        return;
                    });
                });
            }else{
                if((task.isTaskScheduled === false || (task.isTaskScheduled === true && task.taskScheduler.cronEndOn && currentDate >= task.taskScheduler.cronEndOn)) && user === 'system') {
                    crontab.cancelJob(task.cronJobId);
                    taskDao.updateTaskScheduler(task._id, function (err, updatedData) {
                        if (err) {
                            logger.error("Failed to update Task Scheduler: ", err);
                            callback(err, null);
                            return;
                        }
                        logger.debug("Scheduler is ended on for Task. " + task.name);
                        callback(null, updatedData);
                        return;
                    });
                }else {
                    taskDao.updateTaskExecutionCount(task._id, taskExecutionCount, function (err, data) {
                        if (err) {
                            logger.error("Error while updating Task Execution Count");
                        }
                    });
                    task.execute(user, hostProtocol, choiceParam, appData, blueprintIds, task.envId, auditTrailId, function (err, taskRes, historyData) {
                        if (err) {
                            var error = new Error('Failed to execute task.');
                            error.status = 500;
                            return callback(error, null);
                        }
                        if (historyData) {
                            taskRes.historyId = historyData.id;
                        }
                        callback(null, taskRes);
                        return;
                    });
                }
            }

        } else {
            var error1 = new Error('Task Not Found.');
            error1.status = 404;
            return callback(error1, null);
        }
    });
Example #14
0
 (function(id){
     count++;
     cronTab.cancelJob(id);
 })(ids[i]);
Example #15
0
 serialTaskList.push(function (cronJobId,next) {
     cronTab.cancelJob(cronJobId);
     schedulerService.executeSerialScheduledTasks(task, next);
 });