r59038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59037‎ | r59038 | r59039 >
Date:22:43, 13 November 2009
Author:ialex
Status:ok
Tags:
Comment:
Convert lag.php maintenance script to new format (using the Maintenance class)
Modified paths:
  • /trunk/phase3/maintenance/lag.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/lag.php
@@ -1,33 +1,50 @@
22 <?php
33
4 -$wgUseNormalUser = true;
5 -require_once('commandLine.inc');
 4+/**
 5+ * Shows database lag
 6+ *
 7+ * @ingroup Maintenance
 8+ */
69
7 -if ( isset( $options['r'] ) ) {
8 - $lb = wfGetLB();
9 - print 'time ';
10 - for( $i = 0; $i < $lb->getServerCount(); $i++ ) {
11 - $hostname = $lb->getServerName( $i );
12 - printf("%-12s ", $hostname );
 10+require_once( dirname(__FILE__) . '/Maintenance.php' );
 11+
 12+class DatabaseLag extends Maintenance {
 13+ public function __construct() {
 14+ parent::__construct();
 15+ $this->mDescription = "Shows database lag";
 16+ $this->addOption( 'r', "Don't exit immediately, but show the lag every 5 seconds" );
1317 }
14 - print("\n");
15 -
16 - while( 1 ) {
17 - $lags = $lb->getLagTimes();
18 - unset( $lags[0] );
19 - print( gmdate( 'H:i:s' ) . ' ' );
20 - foreach( $lags as $i => $lag ) {
21 - printf("%-12s " , $lag === false ? 'false' : $lag );
 18+
 19+ public function execute() {
 20+ if ( $this->hasOption( 'r' ) ) {
 21+ $lb = wfGetLB();
 22+ $this->output( 'time ' );
 23+ for( $i = 0; $i < $lb->getServerCount(); $i++ ) {
 24+ $hostname = $lb->getServerName( $i );
 25+ $this->output( sprintf( "%-12s ", $hostname ) );
 26+ }
 27+ $this->output( "\n" );
 28+
 29+ while( 1 ) {
 30+ $lags = $lb->getLagTimes();
 31+ unset( $lags[0] );
 32+ $this->output( gmdate( 'H:i:s' ) . ' ' );
 33+ foreach( $lags as $i => $lag ) {
 34+ $this->output( sprintf( "%-12s " , $lag === false ? 'false' : $lag ) );
 35+ }
 36+ $this->output( "\n" );
 37+ sleep( 5 );
 38+ }
 39+ } else {
 40+ $lb = wfGetLB();
 41+ $lags = $lb->getLagTimes();
 42+ foreach( $lags as $i => $lag ) {
 43+ $name = $lb->getServerName( $i );
 44+ $this->output( sprintf( "%-20s %s\n" , $name, $lag === false ? 'false' : $lag ) );
 45+ }
2246 }
23 - print("\n");
24 - sleep(5);
2547 }
26 -} else {
27 - $lb = wfGetLB();
28 - $lags = $lb->getLagTimes();
29 - foreach( $lags as $i => $lag ) {
30 - $name = $lb->getServerName( $i );
31 - printf("%-20s %s\n" , $name, $lag === false ? 'false' : $lag );
32 - }
3348 }
34 -?>
 49+
 50+$maintClass = "DatabaseLag";
 51+require_once( DO_MAINTENANCE );

Status & tagging log