Mwalker has uploaded a new change for review.

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


Change subject: Allow Dumping of Raw STOMP Messages
......................................................................

Allow Dumping of Raw STOMP Messages

Allow a raw dump mode which does not attempt to serialize/deserialize
messages pulled from the queue.

Change-Id: If58ebd33b8aee0d162b7e55afc613a9742f91ba3
---
M Core/DataStores/StompDataStore.php
M Maintenance/EmptyQueueToDump.php
2 files changed, 19 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/56/92556/1

diff --git a/Core/DataStores/StompDataStore.php 
b/Core/DataStores/StompDataStore.php
index 076bae1..11e4442 100644
--- a/Core/DataStores/StompDataStore.php
+++ b/Core/DataStores/StompDataStore.php
@@ -218,16 +218,18 @@
         * @param null|string    $type      The class of message to retrieve 
(if null retrieves all)
         * @param null|string    $id        The correlation ID of the message 
(if null retrieves all)
         * @param string[]       $customSelectors Array of custom STOMP 
selectors (e.g 'gateway=adyen')
+        * @param bool           $deserialize If true will return an object. 
Otherwise will return an array
+        *                                    with keys 'headers' and 'body'.
         *
         * @throws DataStoreTransactionException
         * @throws DataSerializationException
         * @throws DataStoreException
-        * @return KeyedOpaqueStorableObject|null
+        * @return KeyedOpaqueStorableObject|array|null
         */
-       public function queueGetObject( $type = null, $id = null, 
$customSelectors = array() ) {
+       public function queueGetObject( $type = null, $id = null, 
$customSelectors = array(), $deserialize = true ) {
                $msgObj = $this->queueGetObjectRaw( $type, $id, 
$customSelectors );
 
-               if ( $msgObj ) {
+               if ( $msgObj && $deserialize ) {
                        if ( !array_key_exists( 'php-message-class', 
$msgObj->headers ) ) {
                                Logger::warning(
                                        "Message was serialized without key 
php-message-class. Cannot re-instantiate.",
@@ -261,6 +263,11 @@
                        }
 
                        return $classObj;
+               } elseif ( $msgObj && !$deserialize ) {
+                       return array(
+                               'headers' => $msgObj->headers,
+                               'body' => $msgObj->body,
+                       );
                } else {
                        return null;
                }
diff --git a/Maintenance/EmptyQueueToDump.php b/Maintenance/EmptyQueueToDump.php
index 078cbf8..28aca75 100644
--- a/Maintenance/EmptyQueueToDump.php
+++ b/Maintenance/EmptyQueueToDump.php
@@ -28,6 +28,7 @@
                $this->addOption( 'queue', 'queue name to consume from', 'test' 
);
                $this->addOption( 'max-messages', 'At most consume <n> 
messages, 0 is infinite', 10, 'm' );
                $this->addOption( 'outfile', 'File to place JSON encoded 
messages into', 'messages.json', 'f' );
+               $this->addOption( 'raw', 'Do not ensure that extracted messages 
are SmashPig objects' );
                $this->addArgument( 'selector', 'STOMP selector to use', 'true' 
);
                $this->addArgument( 'selector2', 'Additional STOMP 
selectors...', false );
        }
@@ -41,6 +42,8 @@
                $maxMessages = $this->getOption( 'max-messages' );
                $startTime = time();
                $messageCount = 0;
+
+               $raw = $this->getOption( 'raw' );
 
                // Construct the selectors
                $argId = 0;
@@ -63,13 +66,17 @@
                        // ...Ideally we would take the JSON from the store 
directly instead of walking
                        // it through an object
                        try {
-                               $queueObj = $this->datastore->queueGetObject( 
null, null, $selectors );
+                               $queueObj = $this->datastore->queueGetObject( 
null, null, $selectors, !$raw );
 
                                if ( !$queueObj ) {
                                        break;
                                }
 
-                               fwrite( $f, get_class( $queueObj ) . "=" . 
$queueObj->toJson( false ) . "\n" );
+                               if ( $raw ) {
+                                       fwrite( $f, 'raw' . "=" . json_encode( 
$queueObj ) . "\n" );
+                               } else {
+                                       fwrite( $f, get_class( $queueObj ) . 
"=" . $queueObj->toJson( false ) . "\n" );
+                               }
                        } catch( DataSerializationException $ex ) {
                                // We probably caught an anti-message here; log 
the exception and continue on
                                Logger::warning( "Possibly caught an 
antimessage. Not adding to file.", null, $ex );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If58ebd33b8aee0d162b7e55afc613a9742f91ba3
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>

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

Reply via email to