private void reschedule(CronTrigger cronTrigger, ISchedulable schedulable, MySchedulableContext context) {
System.abortJob(cronTrigger.Id);
String newTrigger = schedulable.getNextTriggerString(context);
System.schedule(cronTrigger.CronJobDetail.Name, newTrigger, this);
}
In the code above, I kept getting job already exists or is aborted on the line:
System.abortJob(cronTrigger.Id);
Looking at a couple of questions here:
Apex CronTrigger Throws error while aborting: Job does not exist or is already aborted.
Why Deleting Scheduled Jobs with Apex Suddenly Stopped Working March 2015
So I did:
private void reschedule(CronTrigger cronTrigger, ISchedulable schedulable, MySchedulableContext context) {
if(cronTrigger.Id != Null && cronTrigger.State != 'ERROR' && cronTrigger.State != 'DELETED' ){
System.abortJob(cronTrigger.Id);
}
String newTrigger = schedulable.getNextTriggerString(context);
System.schedule(cronTrigger.CronJobDetail.Name, newTrigger, this);
}
Are there any other states that I should worry about ? For example the Cron Trigger State can also be COMPLETE amongst others and will aborting a COMPLETE job give the same error?