- Removes unused logic to deal with "failed" subscribers
- Updates sending queue worker to handle new mailer response format
This commit is contained in:
@ -115,7 +115,6 @@ class Migrator {
|
|||||||
'count_total mediumint(9) NOT NULL DEFAULT 0,',
|
'count_total mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'count_processed mediumint(9) NOT NULL DEFAULT 0,',
|
'count_processed mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'count_to_process mediumint(9) NOT NULL DEFAULT 0,',
|
'count_to_process mediumint(9) NOT NULL DEFAULT 0,',
|
||||||
'count_failed mediumint(9) NOT NULL DEFAULT 0,',
|
|
||||||
'scheduled_at TIMESTAMP NULL,',
|
'scheduled_at TIMESTAMP NULL,',
|
||||||
'processed_at TIMESTAMP NULL,',
|
'processed_at TIMESTAMP NULL,',
|
||||||
'created_at TIMESTAMP NULL,',
|
'created_at TIMESTAMP NULL,',
|
||||||
|
@ -21,8 +21,10 @@ class SendingQueue {
|
|||||||
$this->mailer_task = ($mailer_task) ? $mailer_task : new MailerTask();
|
$this->mailer_task = ($mailer_task) ? $mailer_task : new MailerTask();
|
||||||
$this->newsletter_task = ($newsletter_task) ? $newsletter_task : new NewsletterTask();
|
$this->newsletter_task = ($newsletter_task) ? $newsletter_task : new NewsletterTask();
|
||||||
$this->timer = ($timer) ? $timer : microtime(true);
|
$this->timer = ($timer) ? $timer : microtime(true);
|
||||||
// abort if execution or sending limit are reached
|
// abort if execution limit is reached
|
||||||
CronHelper::enforceExecutionLimit($this->timer);
|
CronHelper::enforceExecutionLimit($this->timer);
|
||||||
|
// abort if mailing is paused or sending limit has been reached
|
||||||
|
MailerLog::enforceExecutionRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
function process() {
|
function process() {
|
||||||
@ -142,20 +144,22 @@ class SendingQueue {
|
|||||||
$prepared_newsletters,
|
$prepared_newsletters,
|
||||||
$prepared_subscribers
|
$prepared_subscribers
|
||||||
);
|
);
|
||||||
if(!$send_result) {
|
// log error message and schedule retry/pause sending
|
||||||
// update failed/to process list
|
if($send_result['response'] === false) {
|
||||||
$queue->updateFailedSubscribers($prepared_subscribers_ids);
|
MailerLog::processSendingError(
|
||||||
} else {
|
$send_result['operation'],
|
||||||
// update processed/to process list
|
$send_result['error_message']
|
||||||
$queue->updateProcessedSubscribers($prepared_subscribers_ids);
|
);
|
||||||
// log statistics
|
}
|
||||||
StatisticsNewslettersModel::createMultiple($statistics);
|
// update processed/to process list
|
||||||
// update the sent count
|
$queue->updateProcessedSubscribers($prepared_subscribers_ids);
|
||||||
$this->mailer_task->updateSentCount();
|
// log statistics
|
||||||
// enforce sending limit if there are still subscribers left to process
|
StatisticsNewslettersModel::createMultiple($statistics);
|
||||||
if($queue->count_to_process) {
|
// update the sent count
|
||||||
MailerLog::enforceSendingLimit();
|
$this->mailer_task->updateSentCount();
|
||||||
}
|
// abort if sending limit has been reached
|
||||||
|
if($queue->count_to_process) {
|
||||||
|
MailerLog::enforceSendingLimit();
|
||||||
}
|
}
|
||||||
return $queue;
|
return $queue;
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,6 @@ class SendingQueue extends Model {
|
|||||||
if(empty($subscribers['processed'])) {
|
if(empty($subscribers['processed'])) {
|
||||||
$subscribers['processed'] = array();
|
$subscribers['processed'] = array();
|
||||||
}
|
}
|
||||||
if(empty($subscribers['failed'])) {
|
|
||||||
$subscribers['failed'] = array();
|
|
||||||
}
|
|
||||||
return $subscribers;
|
return $subscribers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,22 +94,6 @@ class SendingQueue extends Model {
|
|||||||
$this->updateCount();
|
$this->updateCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFailedSubscribers($failed_subscribers) {
|
|
||||||
$subscribers = $this->getSubscribers();
|
|
||||||
$subscribers['failed'] = array_merge(
|
|
||||||
$subscribers['failed'],
|
|
||||||
$failed_subscribers
|
|
||||||
);
|
|
||||||
$subscribers['to_process'] = array_values(
|
|
||||||
array_diff(
|
|
||||||
$subscribers['to_process'],
|
|
||||||
$failed_subscribers
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$this->subscribers = $subscribers;
|
|
||||||
$this->updateCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateProcessedSubscribers($processed_subscribers) {
|
function updateProcessedSubscribers($processed_subscribers) {
|
||||||
$subscribers = $this->getSubscribers();
|
$subscribers = $this->getSubscribers();
|
||||||
$subscribers['processed'] = array_merge(
|
$subscribers['processed'] = array_merge(
|
||||||
@ -131,10 +112,8 @@ class SendingQueue extends Model {
|
|||||||
|
|
||||||
function updateCount() {
|
function updateCount() {
|
||||||
$this->subscribers = $this->getSubscribers();
|
$this->subscribers = $this->getSubscribers();
|
||||||
$this->count_processed =
|
$this->count_processed = count($this->subscribers['processed']);
|
||||||
count($this->subscribers['processed']) + count($this->subscribers['failed']);
|
|
||||||
$this->count_to_process = count($this->subscribers['to_process']);
|
$this->count_to_process = count($this->subscribers['to_process']);
|
||||||
$this->count_failed = count($this->subscribers['failed']);
|
|
||||||
$this->count_total = $this->count_processed + $this->count_to_process;
|
$this->count_total = $this->count_processed + $this->count_to_process;
|
||||||
if(!$this->count_to_process) {
|
if(!$this->count_to_process) {
|
||||||
$this->processed_at = current_time('mysql');
|
$this->processed_at = current_time('mysql');
|
||||||
|
Reference in New Issue
Block a user