MediaWiki REL1_40
showJobs.php
Go to the documentation of this file.
1<?php
22
23require_once __DIR__ . '/Maintenance.php';
24
37class ShowJobs extends Maintenance {
38 protected static $stateMethods = [
39 'unclaimed' => 'getAllQueuedJobs',
40 'delayed' => 'getAllDelayedJobs',
41 'claimed' => 'getAllAcquiredJobs',
42 'abandoned' => 'getAllAbandonedJobs',
43 ];
44
45 public function __construct() {
46 parent::__construct();
47 $this->addDescription( 'Show number of jobs waiting in primary database' );
48 $this->addOption( 'group', 'Show number of jobs per job type' );
49 $this->addOption( 'list', 'Show a list of all jobs instead of counts' );
50 $this->addOption( 'type', 'Only show/count jobs of a given type', false, true );
51 $this->addOption( 'status', 'Filter list by state (unclaimed,delayed,claimed,abandoned)' );
52 $this->addOption( 'limit', 'Limit of jobs listed' );
53 }
54
55 public function execute() {
56 $typeFilter = $this->getOption( 'type', '' );
57 $stateFilter = $this->getOption( 'status', '' );
58 $stateLimit = (float)$this->getOption( 'limit', INF );
59
60 $group = MediaWikiServices::getInstance()->getJobQueueGroup();
61
62 $filteredTypes = $typeFilter
63 ? [ $typeFilter ]
64 : $group->getQueueTypes();
65 $filteredStates = $stateFilter
66 ? array_intersect_key( self::$stateMethods, [ $stateFilter => 1 ] )
68
69 if ( $this->hasOption( 'list' ) ) {
70 $count = 0;
71 foreach ( $filteredTypes as $type ) {
72 $queue = $group->get( $type );
73 foreach ( $filteredStates as $state => $method ) {
74 foreach ( $queue->$method() as $job ) {
76 $this->output( $job->toString() . " status=$state\n" );
77 if ( ++$count >= $stateLimit ) {
78 return;
79 }
80 }
81 }
82 }
83 } elseif ( $this->hasOption( 'group' ) ) {
84 foreach ( $filteredTypes as $type ) {
85 $queue = $group->get( $type );
86 $delayed = $queue->getDelayedCount();
87 $pending = $queue->getSize();
88 $claimed = $queue->getAcquiredCount();
89 $abandoned = $queue->getAbandonedCount();
90 $active = max( 0, $claimed - $abandoned );
91 if ( ( $pending + $claimed + $delayed + $abandoned ) > 0 ) {
92 $this->output(
93 "{$type}: $pending queued; " .
94 "$claimed claimed ($active active, $abandoned abandoned); " .
95 "$delayed delayed\n"
96 );
97 }
98 }
99 } else {
100 $count = 0;
101 foreach ( $filteredTypes as $type ) {
102 $count += $group->get( $type )->getSize();
103 }
104 $this->output( "$count\n" );
105 }
106 }
107}
108
109$maintClass = ShowJobs::class;
110require_once RUN_MAINTENANCE_IF_MAIN;
Class to both describe a background job and handle jobs.
Definition Job.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Service locator for MediaWiki core services.
Report number of jobs currently waiting in primary database.
Definition showJobs.php:37
execute()
Do the actual work.
Definition showJobs.php:55
__construct()
Default constructor.
Definition showJobs.php:45
static $stateMethods
Definition showJobs.php:38
if(count( $args)< 1) $job
$maintClass
Definition showJobs.php:109