Details
Description
CiviMail gets stuck after delivering the initial batch of emails. I have two mailings that require multiple cron runs to fully deliver but they never progressed for days beyond the 1st batch of 50. The first mailing had 68 recipients, the second had 6000+.
I'm currently using CiviCRM 3.3.1 with Joomla 1.5. This issue first appeared when I upgraded to 3.3, and it has remained after a further upgrade to 3.3.1. There has been no change in configuration as I far as I can tell (I'm not the only administrator).
I've configured CiviMail to send 50 mails at intervals of 5 minutes. The specific mailer settings are:
Mailer batch limit: 50
Mailer job size: (unset)
VERP separator: .
I've also verified that the cron job does run at the right interval (5 minutes).
Having looked through the code and database, I noticed that the scheduled child jobs for the two mailings was not picked up by CRM_Mailing_BAO_Job::runJobs(). Consequently the CiviMail script returns without performing any delivery.
There seems to be 2 issues with the child job query in CRM_Mailing_BAO_Job::runJobs():
SELECT j.* FROM $jobTable j, $mailingTable m
WHERE m.id = j.mailing_id
AND j.is_test = 0
AND ( ( j.start_date IS null
AND j.scheduled_date <= $currentTime
AND j.status = 'Scheduled'
AND j.end_date IS null ) )
AND (j.job_type = 'child')
AND {$mailingACL}
ORDER BY j.mailing_id, j.id
LIMIT 0,1
Firstly, start_date is required to be null. Secondly, status must be set to 'Scheduled'. The problem is both start_date is set and the status changed to 'Running' after a child job is performed for the first time. For this reason, the job is never performed again and child jobs never complete unless all mails were delivered in the first run.
Attached is a patch that addresses this issue. I'm not sure if it's completely sound, given my limited familiarity with the code.