jenkins-bot has submitted this change and it was merged.

Change subject: Retry capture later when donor details are missing
......................................................................


Retry capture later when donor details are missing

Add a new exception class to mark things that can be retried, and
two config keys for retry delay and maximum age.

Bug: T147378
Change-Id: I765746d5efc54f22f40576fd73ef3fd92ca30e00
---
M Core/QueueConsumers/BaseQueueConsumer.php
A Core/RetryableException.php
M PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
M SmashPig.yaml
4 files changed, 34 insertions(+), 3 deletions(-)

Approvals:
  Cdentinger: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Core/QueueConsumers/BaseQueueConsumer.php 
b/Core/QueueConsumers/BaseQueueConsumer.php
index b3e5f26..2bb458c 100644
--- a/Core/QueueConsumers/BaseQueueConsumer.php
+++ b/Core/QueueConsumers/BaseQueueConsumer.php
@@ -5,9 +5,12 @@
 use InvalidArgumentException;
 use PHPQueue\Interfaces\AtomicReadBuffer;
 
+use SmashPig\Core\Configuration;
 use SmashPig\Core\Context;
 use SmashPig\Core\DataStores\DamagedDatabase;
 use SmashPig\Core\Logging\Logger;
+use SmashPig\Core\RetryableException;
+use SmashPig\Core\UtcDate;
 
 /**
  * Facilitates guaranteed message processing using PHPQueue's AtomicReadBuffer
@@ -125,6 +128,21 @@
         * @param Exception $ex
         */
        protected function handleError( $message, Exception $ex ) {
+               if ( $ex instanceof RetryableException ) {
+                       $now = UtcDate::getUtcTimestamp();
+
+                       if ( !isset( $message['source_enqueued_time'] ) ) {
+                               $message['source_enqueued_time'] = 
UtcDate::getUtcTimestamp();
+                       }
+                       $expirationDate = $message['source_enqueued_time'] +
+                               Configuration::getDefaultConfig()->val( 
'requeue-max-age' );
+
+                       if ( $now < $expirationDate ) {
+                               $retryDate = $now + 
Configuration::getDefaultConfig()->val( 'requeue-delay' );
+                               $this->sendToDamagedStore( $message, $ex, 
$retryDate );
+                               return;
+                       }
+               }
                $this->sendToDamagedStore( $message, $ex );
        }
 
diff --git a/Core/RetryableException.php b/Core/RetryableException.php
new file mode 100644
index 0000000..9dc22f7
--- /dev/null
+++ b/Core/RetryableException.php
@@ -0,0 +1,8 @@
+<?php namespace SmashPig\Core;
+
+/**
+ * Throw one of these if the problem might be transient
+ */
+class RetryableException extends SmashPigException {
+
+}
diff --git a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php 
b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
index fb39f08..50a0bc8 100644
--- a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
+++ b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php
@@ -5,6 +5,7 @@
 use SmashPig\Core\Jobs\RunnableJob;
 use SmashPig\Core\Logging\Logger;
 use SmashPig\Core\Logging\TaggedLogger;
+use SmashPig\Core\RetryableException;
 use SmashPig\CrmLink\Messages\DonationInterfaceAntifraudFactory;
 use SmashPig\PaymentProviders\Adyen\AdyenPaymentsInterface;
 use SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation;
@@ -124,9 +125,8 @@
                                // the pending database in case the 
authorization is captured via the console.
                                break;
                        case self::ACTION_MISSING:
-                               // Missing donor details - nothing to do but 
return failure
-                               $success = false;
-                               break;
+                               // Missing donor details - retry later
+                               throw new RetryableException( 'Missing donor 
details' );
                }
 
                return $success;
diff --git a/SmashPig.yaml b/SmashPig.yaml
index d64ebce..6894329 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -191,6 +191,11 @@
             time-limit: 60
             max-messages: 0
 
+    # in seconds
+    requeue-delay: 600
+
+    requeue-max-age: 36000
+
 adyen:
     logging:
         root-context: SmashPig-Adyen

-- 
To view, visit https://gerrit.wikimedia.org/r/315858
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I765746d5efc54f22f40576fd73ef3fd92ca30e00
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to