Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/206312

Change subject: WIP Use DonationQueue for limbo queuing
......................................................................

WIP Use DonationQueue for limbo queuing

Does not affect the orphan slayer.

DEPLOYMENT
Requires that the limbo queue be configured.

We stop emitting antimessages and delete the message directly instead.

The migration will be to:
1) Deploy this patch, and stop producing new antimessages.
2) Consume the remaining antimessages with an offline batch process, such
as the previous revision code, running on the staging server.

Bug: T92921
Change-Id: I637bcba899b3616e9f60207931b28fb9af8051af
---
M gateway_common/gateway.adapter.php
M globalcollect_gateway/globalcollect.adapter.php
M tests/includes/test_gateway/TestingGlobalCollectAdapter.php
3 files changed, 53 insertions(+), 59 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/12/206312/1

diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 182e05c..12f3fff 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -1853,37 +1853,12 @@
                        default:
                                // No action
                                $this->logger->info( "Not sending queue message 
for status {$status}." );
-
-       /**
-        * Function that adds a stomp message to a special 'limbo' queue, for 
data
-        * that is either highly likely or completely guaranteed to be 
bifurcated by
-        * handing the ball to a third-party process.
-        *
-        * @param bool $antiMessage If TRUE message will be formatted to 
destroy a message in the limbo
-        *  queue when the orphan slayer is run.
-        *
-        * @return null
-        */
-       protected function doLimboStompTransaction( $antiMessage = false ) {
-               if ( !$this->getGlobal( 'EnableStomp' ) ){
-                       return;
-               }
-
-               $this->debugarray[] = "Attempting Limbo Stomp Transaction!";
-
-               $transaction = $this->getStompTransaction( $antiMessage );
-
-               try {
-                       WmfFramework::runHooks( 'gwStomp', array( $transaction, 
'limbo' ) );
-               } catch ( Exception $e ) {
-                       $this->logger->critical( "STOMP ERROR. Could not add 
message to 'limbo' queue: {$e->getMessage()} " . json_encode( $transaction ) );
                }
        }
 
        /**
         * Formats an array in preparation for dispatch to a STOMP queue
         *
-        * @param bool $antiMessage If TRUE, message will be prepared to destroy
         * @param bool $recoverTimestamp If TRUE the timestamp will be set to 
any recoverable timestamp
         *  from the transaction. If it cannot be recovered or this argument is 
false, it will take the
         *  current time.
@@ -1892,7 +1867,7 @@
         *
         * TODO: Stop saying "STOMP".
         */
-       protected function getStompTransaction( $antiMessage = false, 
$recoverTimestamp = false ) {
+       protected function getStompTransaction( $recoverTimestamp = false ) {
                $transaction = array(
                        'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
                        'payment_method' => $this->getData_Unstaged_Escaped( 
'payment_method' ),
@@ -1903,33 +1878,29 @@
                        'gateway' => $this->getData_Unstaged_Escaped( 'gateway' 
),
                );
 
-               if ( $antiMessage == true ) {
-                       // As anti-messages only exist to destroy messages all 
we need is the identifier
-                       $transaction['antimessage'] = 'true';
-               } else {
-                       // Else we actually need the rest of the data
-                       $stomp_data = array_intersect_key(
-                               $this->getData_Unstaged_Escaped(),
-                               array_flip( 
$this->dataObj->getStompMessageFields() )
-                       );
+               // Else we actually need the rest of the data
+               $stomp_data = array_intersect_key(
+                       $this->getData_Unstaged_Escaped(),
+                       array_flip( $this->dataObj->getStompMessageFields() )
+               );
 
-                       // The order here is important, values in $transaction 
are considered more definitive
-                       // in case the transaction already had keys with those 
values
-                       $transaction = array_merge( $stomp_data, $transaction );
+               // The order here is important, values in $transaction are 
considered more definitive
+               // in case the transaction already had keys with those values
+               $transaction = array_merge( $stomp_data, $transaction );
 
-                       // And now determine the date; which is annoyingly not 
as easy as one would like it
-                       // if we're attempting to recover some data: ie: we're 
an orphan
-                       $timestamp = null;
-                       if ( $recoverTimestamp === true ) {
-                               if ( !is_null( $this->getData_Unstaged_Escaped( 
'date' ) ) ) {
-                                       $timestamp = 
$this->getData_Unstaged_Escaped( 'date' );
-                               } elseif ( !is_null( 
$this->getData_Unstaged_Escaped( 'ts' ) ) ) {
-                                       // That this works is mildly surprising
-                                       $timestamp = strtotime( 
$this->getData_Unstaged_Escaped( 'ts' ) );
-                               }
+               // And now determine the date; which is annoyingly not as easy 
as one would like it
+               // if we're attempting to recover some data: ie: we're an orphan
+               // FIXME: Can't we make this the default?
+               $timestamp = null;
+               if ( $recoverTimestamp === true ) {
+                       if ( !is_null( $this->getData_Unstaged_Escaped( 'date' 
) ) ) {
+                               $timestamp = $this->getData_Unstaged_Escaped( 
'date' );
+                       } elseif ( !is_null( $this->getData_Unstaged_Escaped( 
'ts' ) ) ) {
+                               // That this works is mildly surprising
+                               $timestamp = strtotime( 
$this->getData_Unstaged_Escaped( 'ts' ) );
                        }
-                       $transaction['date'] = ( $timestamp === null ) ? time() 
: $timestamp;
                }
+               $transaction['date'] = ( $timestamp === null ) ? time() : 
$timestamp;
 
                return $transaction;
        }
@@ -2554,6 +2525,17 @@
                DonationQueue::instance()->push( $this->getStompTransaction(), 
$queue );
        }
 
+       protected function setLimboMessage( $queue ) {
+               // FIXME: log the key and raw queue name.
+               $this->logger->info( "Setting transaction in limbo store 
[$queue]" );
+               DonationQueue::instance()->set( $this->getCorrelationID(), 
$this->getStompTransaction(), $queue );
+       }
+
+       protected function deleteLimboMessage( $queue ) {
+               $this->logger->info( "Clearing transaction from limbo store 
[$queue]" );
+               DonationQueue::instance()->delete( $this->getCorrelationID(), 
$queue );
+       }
+
        /**
         * If there are things about a transaction that we need to stash in the
         * transaction's definition (defined in a local defineTransactions() ), 
we
diff --git a/globalcollect_gateway/globalcollect.adapter.php 
b/globalcollect_gateway/globalcollect.adapter.php
index 8efc5e7..3d94f68 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -25,6 +25,7 @@
        const GATEWAY_NAME = 'Global Collect';
        const IDENTIFIER = 'globalcollect';
        const GLOBAL_PREFIX = 'wgGlobalCollectGateway';
+       const CC_LIMBO_QUEUE = 'globalcollect-cc-limbo';
 
        public function getCommunicationType() {
                return 'xml';
@@ -1178,7 +1179,7 @@
                        $this->logger->info( $logmsg );
                        //add an antimessage for everything but orphans
                        $this->logger->info( 'Adding Antimessage' );
-                       $this->doLimboStompTransaction( true );
+                       $this->deleteLimboMessage( self::CC_LIMBO_QUEUE );
                } else { //this is an orphan transaction.
                        $is_orphan = true;
                        //have to change this code range: All these are usually 
"pending" and
@@ -1354,8 +1355,7 @@
                                        $this->finalizeInternalStatus( 
'complete' );
                                        //get the old status from the first 
txn, and add in the part where we set the payment.
                                        $this->setTransactionResult( "Original 
Response Status (pre-SET_PAYMENT): " . $original_status_code, 'txn_message' );
-                                       $this->runPostProcessHooks();  //stomp 
is in here
-                                       $add_antimessage = true; //TODO: use or 
remove
+                                       $this->runPostProcessHooks();  // 
Queueing is in here.
                                } else {
                                        $this->finalizeInternalStatus( 'failed' 
);
                                        $problemflag = true;
@@ -1439,12 +1439,14 @@
                                        if (isset($result['status']) && 
$result['status'] === true)
                                        {
                                                $this->finalizeInternalStatus( 
'complete' );
-                                               $this->doLimboStompTransaction( 
true );
                                        } else {
                                                $this->finalizeInternalStatus( 
'failed' );
                                                //get the old status from the 
first txn, and add in the part where we set the payment.
                                                $this->setTransactionResult( 
"Original Response Status (pre-SET_PAYMENT): " . $original_status_code, 
'txn_message' );
                                        }
+
+                                       // We won't need the limbo message 
again, either way, so cancel it.
+                                       $this->deleteLimboMessage( 'limbo' );
                                }
             }
         }
@@ -2364,11 +2366,15 @@
         */
        protected function post_process_insert_orderwithpayment(){
                //yeah, we absolutely want to do this for every one of these.
-               if ( $this->getTransactionStatus() === true ) {
+               if ( $this->getTransactionStatus() ) {
                        $data = $this->getTransactionData();
                        $action = $this->findCodeAction( 'GET_ORDERSTATUS', 
'STATUSID', $data['STATUSID'] );
-                       if ($action != 'failed'){
-                               $this->doLimboStompTransaction();
+                       if ( $action !== 'failed' ) {
+                               if ( $this->getData_Unstaged_Escaped( 
'payment_method' ) === 'cc' ) {
+                                       $this->setLimboMessage( 
self::CC_LIMBO_QUEUE );
+                               } else {
+                                       $this->setLimboMessage( 'limbo' );
+                               }
                        }
                }
        }
diff --git a/tests/includes/test_gateway/TestingGlobalCollectAdapter.php 
b/tests/includes/test_gateway/TestingGlobalCollectAdapter.php
index 6c58e20..1f4fce9 100644
--- a/tests/includes/test_gateway/TestingGlobalCollectAdapter.php
+++ b/tests/includes/test_gateway/TestingGlobalCollectAdapter.php
@@ -85,10 +85,16 @@
 
        /**
         * Stub out the limboStomp fn and record the calls
-        * @param type $antiMessage
         */
-       public function doLimboStompTransaction( $antiMessage = false ) {
-               $this->limbo_stomps[] = $antiMessage;
+       public function setLimboMessage( $queue ) {
+               $this->limbo_stomps[] = false;
+       }
+
+       /**
+        * Stub out the limboStomp fn and record the calls
+        */
+       public function deleteLimboMessage( $queue ) {
+               $this->limbo_stomps[] = true;
        }
 
        //@TODO: That minfraud jerk needs its own isolated tests.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I637bcba899b3616e9f60207931b28fb9af8051af
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>

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

Reply via email to