Adamw has uploaded a new change for review.

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


Change subject: WIP transactional datastores
......................................................................

WIP transactional datastores

Change-Id: I81d8a837fa46fb269f5bb9fd2aa61e15ecbb19f3
---
M SmashPig/Core/DataStores/KeyedOpaqueDataStore.php
M SmashPig/Core/DataStores/StompDataStore.php
2 files changed, 38 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/PaymentsListeners 
refs/changes/70/52170/1

diff --git a/SmashPig/Core/DataStores/KeyedOpaqueDataStore.php 
b/SmashPig/Core/DataStores/KeyedOpaqueDataStore.php
index bd891e7..c48455e 100644
--- a/SmashPig/Core/DataStores/KeyedOpaqueDataStore.php
+++ b/SmashPig/Core/DataStores/KeyedOpaqueDataStore.php
@@ -67,4 +67,10 @@
         * Acknowledges and replaces into the backing data store the current 
queue object
         */
        abstract public function queueIgnoreObject();
-}
\ No newline at end of file
+
+       abstract public function beginTransaction();
+
+       abstract public function commitTransaction();
+
+       abstract public function rollbackTransaction();
+}
diff --git a/SmashPig/Core/DataStores/StompDataStore.php 
b/SmashPig/Core/DataStores/StompDataStore.php
index 3a5c0ad..7ae12af 100644
--- a/SmashPig/Core/DataStores/StompDataStore.php
+++ b/SmashPig/Core/DataStores/StompDataStore.php
@@ -23,6 +23,8 @@
        /** @var object If not null, the current object being dealt with by the 
queue functions */
        protected $queueMsg = null;
 
+       protected $transaction = null;
+
        /**
         * Create a new STOMP data store from a stored configuration node.
         *
@@ -90,6 +92,10 @@
                        'persistent' => 'true', // So the message doesn't 
disappear when the server restarts
                        'php-message-class' => $objClass,       // Sneakyness! 
No parameter can have '-' in it's name so this is safe!
                );
+
+               if ( $this->transaction !== null ) {
+                       $headers['transaction'] = $this->transaction;
+               }
 
                // Populate with custom keys
                foreach ( $objKeys as $keyName => $keyValue ) {
@@ -336,7 +342,7 @@
                }
 
                Logger::debug( "Acking STOMP message" );
-               $this->stompObj->ack( $this->queueMsg );
+               $this->stompObj->ack( $this->queueMsg, $this->queueMsg->headers 
);
 
                Logger::debug( "Re-adding STOMP message to queue" );
                $sent = $this->stompObj->send( $this->queue_id, 
$this->queueMsg->body, $this->queueMsg->headers );
@@ -349,4 +355,28 @@
                $this->queueMsg = null;
                Logger::info( "STOMP message requeued from '{$this->queue_id}' 
on '{$this->uri}'" );
        }
+
+       public function beginTransaction() {
+               if ( $this->transaction !== null ) {
+                       throw new DataStoreTransactionException( "Transaction 
in progress, cannot begin another." );
+               }
+               $this->transaction = mt_rand();
+               $this->stompObj->begin( $this->transaction );
+       }
+
+       public function commitTransaction() {
+               if ( $this->transaction === null ) {
+                       throw new DataStoreTransactionException( "No 
transaction in progress, cannot commit." );
+               }
+               $this->stompObj->commit( $this->transaction );
+               $this->transaction = null;
+       }
+
+       public function rollbackTransaction() {
+               if ( $this->transaction === null ) {
+                       throw new DataStoreTransactionException( "No 
transaction in progress, cannot rollback." );
+               }
+               $this->stompObj->abort( $this->transaction );
+               $this->transaction = null;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I81d8a837fa46fb269f5bb9fd2aa61e15ecbb19f3
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/PaymentsListeners
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to