I am calling a queueable from batch class and vice-versa. And now got stuck in the infinite loop of execution of the batch and queueable classes in the apex.How can I abort it. When I try to abort the job from Apex jobs it finishes its execution and fails to abort it. Is there any solution to that or will it just go on continuously?
2 Answers
If your batch does not explicitly set a delay when enqueuing, you could set the org-wide queueable delay to a high value, wait for the queueables to be enqueued then kill (abort) them.
An alternative is to ensure deployment allows pending apex to be updated and deploy a change to the batch code to prevent it enqueuing the queueables.
This is untested, but I'd try something like this from Execute Anonymous:
for(AsyncApexJob job : [SELECT Id
FROM AsyncApexJob
WHERE Status IN('Holding', 'Preparing', 'Processing', 'Queued')
AND ApexClass.Name IN('MyBatchClass', 'MyQueueableClass')]) {
System.abortJob(job.Id);
}
If this doesn't kill all the jobs, I'd wrap it (strange as it would look like) in a loop that does the whole shebang ten times. Because I'd suspect that new jobs can get created while old jobs are aborted, and the former need to be killed ASAP too.