From 909ad86e33799178bf0d6d705c9470a62d6c7d8d Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 21 Apr 2016 21:36:37 -0400 Subject: [PATCH 1/2] - Recalculates the number of processed/to process subscribers if the original count does not the current count from the database --- lib/Cron/Workers/SendingQueue.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Cron/Workers/SendingQueue.php b/lib/Cron/Workers/SendingQueue.php index 5470d727ad..ed5bf80a0a 100644 --- a/lib/Cron/Workers/SendingQueue.php +++ b/lib/Cron/Workers/SendingQueue.php @@ -55,6 +55,12 @@ class SendingQueue { $subscribers_ids) { $subscribers = Subscriber::whereIn('id', $subscribers_ids) ->findArray(); + // recalculate the number of subscribers if the total to process count + // does not match the number of subscribers in the database + if (count($subscribers_ids) !== count($subscribers)) { + $subscibers_to_exclude = array_diff($subscribers_ids, Helpers::arrayColumn($subscribers, 'id')); + $queue->subscribers->to_process = array_diff($queue->subscribers->to_process, $subscibers_to_exclude); + } $queue->subscribers = call_user_func_array( array( $this, From 5f45c6cc743614e86f26e1dcec50186d09b5f3a2 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 22 Apr 2016 09:47:53 -0400 Subject: [PATCH 2/2] - Extracts subscriber recalculation into a spearate method - Updates subscriber recalculation logic --- lib/Cron/Workers/SendingQueue.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Cron/Workers/SendingQueue.php b/lib/Cron/Workers/SendingQueue.php index ed5bf80a0a..88de77c3a3 100644 --- a/lib/Cron/Workers/SendingQueue.php +++ b/lib/Cron/Workers/SendingQueue.php @@ -55,11 +55,16 @@ class SendingQueue { $subscribers_ids) { $subscribers = Subscriber::whereIn('id', $subscribers_ids) ->findArray(); - // recalculate the number of subscribers if the total to process count - // does not match the number of subscribers in the database if (count($subscribers_ids) !== count($subscribers)) { - $subscibers_to_exclude = array_diff($subscribers_ids, Helpers::arrayColumn($subscribers, 'id')); - $queue->subscribers->to_process = array_diff($queue->subscribers->to_process, $subscibers_to_exclude); + $queue->subscribers->to_process = $this->recalculateSubscriberCount( + Helpers::arrayColumn($subscribers, 'id'), + $subscribers_ids, + $queue->subscribers->to_process + ); + } + if (!count($queue->subscribers->to_process)) { + $this->updateQueue($queue); + continue; } $queue->subscribers = call_user_func_array( array( @@ -356,6 +361,12 @@ class SendingQueue { return; } + function recalculateSubscriberCount( + $found_subscriber, $existing_subscribers, $subscribers_to_process) { + $subscibers_to_exclude = array_diff($existing_subscribers, $found_subscriber); + return array_diff($subscribers_to_process, $subscibers_to_exclude); + } + private function joinObject($object = array()) { return implode($this->divider, $object); }