Some time we need to update schedule task attribute like time stump; so that when the schedule task execute next time it can start executing after that time stump. we can use the below code to achieve that.
private void updateSchedulerTimeStamp(Date curTime,String scheduledTaskName)
{
try
{
String currentTime = curTime.toString();
SimpleDateFormat lastExecutionTimeParser1 = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
curTime = lastExecutionTimeParser1.parse(currentTime);
String curDate=sdf.format(curTime);
HashMap <String,String> hashmap = new HashMap<String,String>();
hashmap.put("Task Scheduler.Name", scheduledTaskName);
tcSchedulerOperationsIntf tcSchOper = (tcSchedulerOperationsIntf) Platform.getService(tcSchedulerOperationsIntf.class);
tcResultSet tcresultset = tcSchOper.findScheduleTasks(hashmap);
if(tcresultset != null && tcresultset.getRowCount() > 0)
{
tcresultset.goToRow(0);
long schedularKey = tcresultset.getLongValue("Task Scheduler.Key");
String schedularKeyStr = String.valueOf(schedularKey);
hashmap.clear();
hashmap.put("Task Scheduler.Key", schedularKeyStr);
hashmap.put("Task Scheduler.Task Attributes.Name", "Last Execution Time");
tcResultSet tcresultset1 = tcSchOper.findScheduleTaskAttributes(hashmap);
if(tcresultset1 != null && tcresultset1.getRowCount()>0){
tcresultset1.goToRow(0);
long scheduleTaskAtrKey = tcresultset1.getLongValue("Task Scheduler.Task Attributes.Key");
hashmap.put("Task Scheduler.Task Attributes.Value", curDate);
tcSchOper.updateScheduleTaskAttribute(schedularKey,scheduleTaskAtrKey, hashmap);
}
else{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Resultset is null: ");
}
}
}
catch(Exception e)
{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Exception:"+e);
}
}
private void updateSchedulerTimeStamp(Date curTime,String scheduledTaskName)
{
try
{
String currentTime = curTime.toString();
SimpleDateFormat lastExecutionTimeParser1 = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
curTime = lastExecutionTimeParser1.parse(currentTime);
String curDate=sdf.format(curTime);
HashMap <String,String> hashmap = new HashMap<String,String>();
hashmap.put("Task Scheduler.Name", scheduledTaskName);
tcSchedulerOperationsIntf tcSchOper = (tcSchedulerOperationsIntf) Platform.getService(tcSchedulerOperationsIntf.class);
tcResultSet tcresultset = tcSchOper.findScheduleTasks(hashmap);
if(tcresultset != null && tcresultset.getRowCount() > 0)
{
tcresultset.goToRow(0);
long schedularKey = tcresultset.getLongValue("Task Scheduler.Key");
String schedularKeyStr = String.valueOf(schedularKey);
hashmap.clear();
hashmap.put("Task Scheduler.Key", schedularKeyStr);
hashmap.put("Task Scheduler.Task Attributes.Name", "Last Execution Time");
tcResultSet tcresultset1 = tcSchOper.findScheduleTaskAttributes(hashmap);
if(tcresultset1 != null && tcresultset1.getRowCount()>0){
tcresultset1.goToRow(0);
long scheduleTaskAtrKey = tcresultset1.getLongValue("Task Scheduler.Task Attributes.Key");
hashmap.put("Task Scheduler.Task Attributes.Value", curDate);
tcSchOper.updateScheduleTaskAttribute(schedularKey,scheduleTaskAtrKey, hashmap);
}
else{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Resultset is null: ");
}
}
}
catch(Exception e)
{
logger.finest("CLASS_NAME - Nirupam - in updateSchedulerTimeStamp Method :Exception:"+e);
}
}