We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 1f507047 authored by attilak's avatar attilak

Outsource filter notifications to resource model

parent 2dfd893e
...@@ -341,22 +341,8 @@ class Cron ...@@ -341,22 +341,8 @@ class Cron
$this->_order = null; $this->_order = null;
// execute notifications from 2 minute or earlier because order could not yet been created by magento
$dateStart = new \DateTime();
$dateStart->modify('-5 day');
$dateEnd = new \DateTime();
$dateEnd->modify('-1 minute');
$dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true];
// create collection
$notifications = $this->_notificationFactory->create(); $notifications = $this->_notificationFactory->create();
$notifications->addFieldToFilter('done', 0); $notifications->notificationsToProcessFilter();
$notifications->addFieldToFilter('processing', 0);
$notifications->addFieldToFilter('created_at', $dateRange);
$notifications->addFieldToFilter('error_count', ['lt' => Notification::MAX_ERROR_COUNT]);
// Process the notifications in ascending order by creation date and event_code
$notifications->getSelect()->order('created_at ASC')->order('event_code ASC');
// OFFER_CLOSED notifications needs to be at least 10 minutes old to be processed // OFFER_CLOSED notifications needs to be at least 10 minutes old to be processed
$offerClosedMinDate = new \DateTime(); $offerClosedMinDate = new \DateTime();
......
...@@ -46,4 +46,30 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab ...@@ -46,4 +46,30 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
$this->addFieldToFilter('created_at', $dateRange); $this->addFieldToFilter('created_at', $dateRange);
return $this; return $this;
} }
/**
* Filter the notifications table to get non processed or done notifications without 5 or more errors older than
* 2 minutes but not older than 5 days, ordered by created_at and event_code columns
*
* @return $this
*/
public function notificationsToProcessFilter()
{
// execute notifications from 2 minute or earlier because order could not yet been created by magento
$dateStart = new \DateTime();
$dateStart->modify('-5 day');
$dateEnd = new \DateTime();
$dateEnd->modify('-1 minute');
$dateRange = ['from' => $dateStart, 'to' => $dateEnd, 'datetime' => true];
$this->addFieldToFilter('done', 0);
$this->addFieldToFilter('processing', 0);
$this->addFieldToFilter('created_at', $dateRange);
$this->addFieldToFilter('error_count', ['lt' => \Adyen\Payment\Model\Notification::MAX_ERROR_COUNT]);
// Process the notifications in ascending order by creation date and event_code
$this->getSelect()->order('created_at ASC')->order('event_code ASC');
return $this;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment