MediaWiki  REL1_24
showJobs.php
Go to the documentation of this file.
00001 <?php
00028 require_once __DIR__ . '/Maintenance.php';
00029 
00036 class ShowJobs extends Maintenance {
00037     public function __construct() {
00038         parent::__construct();
00039         $this->mDescription = "Show number of jobs waiting in master database";
00040         $this->addOption( 'group', 'Show number of jobs per job type' );
00041         $this->addOption(
00042             'list',
00043             'Show a complete list of all jobs in a machine-readable format, instead of statistics'
00044         );
00045     }
00046 
00047     public function execute() {
00048         $group = JobQueueGroup::singleton();
00049         if ( $this->hasOption( 'list' ) ) {
00050             foreach ( $group->getQueueTypes() as $type ) {
00051                 $queue = $group->get( $type );
00052                 foreach ( $queue->getAllQueuedJobs() as $job ) {
00053                     $this->output( $job->toString() . " status=unclaimed\n" );
00054                 }
00055                 foreach ( $queue->getAllDelayedJobs() as $job ) {
00056                     $this->output( $job->toString() . " status=delayed\n" );
00057                 }
00058             }
00059         } elseif ( $this->hasOption( 'group' ) ) {
00060             foreach ( $group->getQueueTypes() as $type ) {
00061                 $queue = $group->get( $type );
00062                 $delayed = $queue->getDelayedCount();
00063                 $pending = $queue->getSize();
00064                 $claimed = $queue->getAcquiredCount();
00065                 $abandoned = $queue->getAbandonedCount();
00066                 $active = max( 0, $claimed - $abandoned );
00067                 if ( ( $pending + $claimed + $delayed + $abandoned ) > 0 ) {
00068                     $this->output(
00069                         "{$type}: $pending queued; " .
00070                         "$claimed claimed ($active active, $abandoned abandoned); " .
00071                         "$delayed delayed\n"
00072                     );
00073                 }
00074             }
00075         } else {
00076             $count = 0;
00077             foreach ( $group->getQueueTypes() as $type ) {
00078                 $count += $group->get( $type )->getSize();
00079             }
00080             $this->output( "$count\n" );
00081         }
00082     }
00083 }
00084 
00085 $maintClass = "ShowJobs";
00086 require_once RUN_MAINTENANCE_IF_MAIN;