2

Hi so we have a couple of Apex batch jobs that run continuously in our org. One runs every five minutes and one runs every fifteen minutes. In the batch's finish methods, the two reschedule themselves appropriately. However, the past couple of weeks, the jobs have been randomly not scheduling without warning. The last job to run doesn't have any errors but will not schedule.

job view

The gap in the middle is where we noticed the issue and restarted the job. I'm attempting to enable debug logs but it's difficult without knowing when or why the scheduling doesn't happen.

Messaging_SendMessageBatchScheduler__c msgBatchSchedular = Messaging_SendMessageBatchScheduler__c.getValues('Batch Scheduling Time');
if(msgBatchSchedular != null){
    Integer scheduleTime = Integer.valueOf(msgBatchSchedular.RC_SMS_Status_Batch_ScheduleTime_In_Mins__c);
    if(scheduleTime != null){
        if(!Test.isRunningTest()){
            System.scheduleBatch(new Messaging_RCSMSStatusBatch(), 'Check Sent SMS Status Batch', scheduleTime, 70);
        }
    }
}

That's the finish method.

5
  • have you tried looking at debug logs to see if the executions have exceptions thrown, or limits exceeded? When you say the "last job" doesn't have any errors, how have you verified this?
    – Phil W
    Mar 13, 2019 at 17:29
  • Well typically if it has too many HTTP callouts, or DML statements, etc. it will list the error in the errors column on the Apex jobs view. Here the last auto scheduled batch says batches 1, batches processed 1, failures 0 but then didn't schedule the next job. Also, whenever there are failures, the finish method still executes and schedules the next job normally. It's been difficult to enable debug logs due to the sporadic nature of the issue. Typically happens once a week on a job that runs every five minutes.
    – Dylan
    Mar 13, 2019 at 18:43
  • Perhaps enable error level only for system and apex and just keep it going for the user that runs these batches?
    – Phil W
    Mar 13, 2019 at 20:59
  • so you know the finish() method schedules the next job and concludes normally? how do you know this? You could persist the scheduledJobId that System.scheduleBatch returns and gain insight.
    – cropredy
    Mar 13, 2019 at 21:34
  • No in this case I assume it didn't execute the finish method. I just meant whenever one of the self-scheduling jobs has an error, it still schedules itself normally.
    – Dylan
    Mar 14, 2019 at 18:02

1 Answer 1

2

We have some batch apex jobs that are modeled in the same way. We recently had an issue where the job gut hung. It got stuck in the Scheduled Jobs page but it never made it to the Apex Jobs page (if you know what I mean).

When we chatted with support, they basically said that Scheduled Jobs are not guaranteed to run.

So we wrote some logic now so that if a job gets hung in Scheduled Jobs page (determined by checking whether the Next Scheduled Run date is in the past), we abort the hung job & reschedule it.

We haven't experienced any more hung jobs since. Hope this helps.

1
  • Thanks! That's interesting. So maybe the CronTrigger exists for the job but it's NextFireTime passed and it just got hung up.
    – Dylan
    Mar 18, 2019 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .