Adamw has uploaded a new change for review. https://gerrit.wikimedia.org/r/96685
Change subject: WIP (FR #1144) Damaged queue navigator ...................................................................... WIP (FR #1144) Damaged queue navigator Change-Id: I0aa2465cb945b3a5c13bdb5761a8b36a9b373a55 --- M sites/all/modules/wmf_common/Queue.php M sites/all/modules/wmf_common/wmf_common.module 2 files changed, 87 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/85/96685/1 diff --git a/sites/all/modules/wmf_common/Queue.php b/sites/all/modules/wmf_common/Queue.php index e694207..51bc9d2 100644 --- a/sites/all/modules/wmf_common/Queue.php +++ b/sites/all/modules/wmf_common/Queue.php @@ -90,6 +90,31 @@ return $processed; } + /** + * Get several messages from the head of a queue, without acknowledging. + */ + function peekMultiple( $queue, $count ) { + # FIXME: prefetchPolicy, timeout param? + + $queue = $this->normalizeQueueName( $queue ); + $con = $this->getFreshConnection(); + + // HACK + $con->setReadTimeout( 1 ); + $con->prefetchSize = $count; + + $con->subscribe( $queue, array( 'ack' => 'client' ) ); + $messages = array(); + while ( $con->hasFrameToRead() && $count-- >= 0 ) { + $msg = $con->readFrame(); + if ( !$msg ) { + break; + } + $messages[] = $msg; + } + return $messages; + } + function getByCorrelationId( $queue, $correlationId ) { $con = $this->getFreshConnection(); $properties = array( diff --git a/sites/all/modules/wmf_common/wmf_common.module b/sites/all/modules/wmf_common/wmf_common.module index 808f707..c279f5d 100644 --- a/sites/all/modules/wmf_common/wmf_common.module +++ b/sites/all/modules/wmf_common/wmf_common.module @@ -69,6 +69,12 @@ 'page callback' => 'drupal_get_form', 'page arguments' => array( 'wmf_common_settings' ), ); + $items['queue/damaged'] = array( + 'title' => 'Browse all damaged messages', + 'access arguments' => array( 'manipulate queues' ), + 'page callback' => 'drupal_get_form', + 'page arguments' => array( 'wmf_common_queue_browser_form' ), + ); $items['queue/%/%'] = array( 'access arguments' => array( 'manipulate queues' ), 'page callback' => 'drupal_get_form', @@ -172,6 +178,62 @@ return system_settings_form($form); } +function wmf_common_queue_browser_form( $form, &$form_state ) { + $q = queue2civicrm_stomp(); + + $hardcoded_queues = array( + 'recurring-damaged', + 'test-donations-damaged', + 'refund-damaged', + ); + + $allMsgs = array(); + $pageSize = 100; + foreach ( $hardcoded_queues as $queue ) { + $msgs = $q->peekMultiple( $queue, $pageSize ); + $pageSize -= count( $msgs ); + $allMsgs = array_merge( $allMsgs, $msgs ); + } + + $rows = array(); + foreach ( $allMsgs as $msg ) { + $damaged_queue = str_replace( '/queue/', '', $msg->headers['destination'] ); + $queue = str_replace( '-damaged', '', $damaged_queue ); + if ( !empty( $msg->headers['correlation-id'] ) ) { + $id = $msg->headers['correlation-id']; + } else { + $id = $msg->headers['message-id']; + } + + $rows[] = array( + $msg->headers['error'], + $queue, + l( $id, $q->item_url( $msg ) ), + ); + } + + + $table_html = theme_table( array( + 'header' => array( + 'Error', + 'Queue', + 'ID', + ), + 'rows' => $rows, + 'empty' => 'Nothing in the damaged queues! Be very suspicious...', + 'attributes' => array(), + 'caption' => t( 'Damaged messages' ), + 'colgroups' => array(), + 'sticky' => true, + ) ).theme( 'pager' ); + + $form['table'] = array( + '#markup' => $table_html, + ); + + return $form; +} + function wmf_common_queue_item_form( $form, &$form_state, $queue, $correlationId ) { $q = queue2civicrm_stomp(); -- To view, visit https://gerrit.wikimedia.org/r/96685 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0aa2465cb945b3a5c13bdb5761a8b36a9b373a55 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Adamw <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits