I want to schedule a job every 15 mins, for now I have created a scheduler class and using 4 statements to schedule it, but then again there is no guarantee that a job might complete itself in 15 mins and there might be the need to abort the next one while the first one is still being executed. I was planning on aborting the second job in execute method of Schedular using Cron Trigger to get the list of job if it's still executing and then abort the next acquired job with the help of job name.Something like this:
List<CronTrigger> cronTriggerList =[SELECT CronJobDetail.Name, CronExpression, OwnerId FROM CronTrigger WHERE CronJobDetail.JobType = '7' and State='EXECUTING' and CronJobDetail.Name like :Name+'%'];
if(!cronTriggerList.isEmpty() && cronTriggerList.size()>0)
{
List<CronTrigger> cronTriggerList01 =[SELECT id,CronJobDetail.Name, CronExpression, OwnerId FROM CronTrigger WHERE CronJobDetail.JobType = '7' and State='ACQUIRED' and CronJobDetail.Name like :Name+'%'];
for(CronTrigger ct:cronTriggerList01)
{
System.abortJob(ct.id);
}
}
My question does it make more sense to schedule the job in finish method of a batch rather than aborting it from execute method in Scheduler?