MediaWiki  REL1_23
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( 'list', 'Show a complete list of all jobs in a machine-readable format, instead of statistics' );
00042     }
00043 
00044     public function execute() {
00045         $group = JobQueueGroup::singleton();
00046         if ( $this->hasOption( 'list' ) ) {
00047             foreach ( $group->getQueueTypes() as $type ) {
00048                 $queue = $group->get( $type );
00049                 foreach ( $queue->getAllQueuedJobs() as $job ) {
00050                     $this->output( $job->toString() . " status=unclaimed\n" );
00051                 }
00052                 foreach ( $queue->getAllDelayedJobs() as $job ) {
00053                     $this->output( $job->toString() . " status=delayed\n" );
00054                 }
00055             }
00056         } elseif ( $this->hasOption( 'group' ) ) {
00057             foreach ( $group->getQueueTypes() as $type ) {
00058                 $queue = $group->get( $type );
00059                 $delayed = $queue->getDelayedCount();
00060                 $pending = $queue->getSize();
00061                 $claimed = $queue->getAcquiredCount();
00062                 $abandoned = $queue->getAbandonedCount();
00063                 $active = max( 0, $claimed - $abandoned );
00064                 if ( ( $pending + $claimed + $delayed ) > 0 ) {
00065                     $this->output(
00066                         "{$type}: $pending queued; " .
00067                         "$claimed claimed ($active active, $abandoned abandoned); " .
00068                         "$delayed delayed\n"
00069                     );
00070                 }
00071             }
00072         } else {
00073             $count = 0;
00074             foreach ( $group->getQueueTypes() as $type ) {
00075                 $count += $group->get( $type )->getSize();
00076             }
00077             $this->output( "$count\n" );
00078         }
00079     }
00080 }
00081 
00082 $maintClass = "ShowJobs";
00083 require_once RUN_MAINTENANCE_IF_MAIN;