Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PW-4149] add processing time to notifications #142

Merged
merged 5 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Components/Builder/NotificationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ public function fromParams($params)
$notification->setErrorDetails($params['reason']);
}

if (isset($params['eventCode']) && isset($params['success'])) {
$notification->setProcessedAt($this->getProcessingTime($notification));
cyattilakiss marked this conversation as resolved.
Show resolved Hide resolved
}

return $notification;
}

/**
* Set delay in processing time for certain notifications.
*
* @param Notification $notification
* @return \DateTime
*/
private function getProcessingTime(Notification $notification): \DateTime
{
$processedAt = new \DateTime();
switch ($notification->getEventCode()) {
case 'AUTHORISATION':
if (!$notification->isSuccess()) {
$processedAt = $processedAt->add(new \DateInterval('PT30M'));
}
break;
case 'OFFER_CLOSED':
$processedAt = $processedAt->add(new \DateInterval('PT30M'));
break;
default:
break;
}

return $processedAt;
}
}
2 changes: 2 additions & 0 deletions Components/NotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public function getNextNotificationToHandle()
{
$builder = $this->notificationRepository->createQueryBuilder('n');
$builder->where("n.status = :statusReceived OR n.status = :statusRetry")
->where('(n.processedAt <= :processingTime OR n.processedAt IS NULL)')
->orderBy('n.updatedAt', 'ASC')
->setParameter('statusReceived', NotificationStatus::STATUS_RECEIVED)
->setParameter('statusRetry', NotificationStatus::STATUS_RETRY)
->setParameter('processingTime', new \DateTime())
->setMaxResults(1);

return $builder->getQuery()->getSingleResult();
Expand Down
24 changes: 24 additions & 0 deletions Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class Notification extends ModelEntity implements \JsonSerializable
*/
private $updatedAt;

/**
* @var \DateTime
* @ORM\Column(name="processed_at", type="datetime", nullable=true)
*/
private $processedAt;

/**
* @var string
* @ORM\Column(name="status", type="text")
Expand Down Expand Up @@ -217,6 +223,24 @@ public function setUpdatedAt(\DateTime $updatedAt): Notification
return $this;
}

/**
* @return \DateTime
*/
public function getProcessedAt(): \DateTime
{
return $this->processedAt;
}

/**
* @param \DateTime $processedAt
* @return Notification
*/
public function setProcessedAt(\DateTime $processedAt): Notification
{
$this->processedAt = $processedAt;
return $this;
}

/**
* @return string
*/
Expand Down