MediaWiki REL1_39
showJobs.php
Go to the documentation of this file.
1<?php
29
30require_once __DIR__ . '/Maintenance.php';
31
38class ShowJobs extends Maintenance {
39 protected static $stateMethods = [
40 'unclaimed' => 'getAllQueuedJobs',
41 'delayed' => 'getAllDelayedJobs',
42 'claimed' => 'getAllAcquiredJobs',
43 'abandoned' => 'getAllAbandonedJobs',
44 ];
45
46 public function __construct() {
47 parent::__construct();
48 $this->addDescription( 'Show number of jobs waiting in primary database' );
49 $this->addOption( 'group', 'Show number of jobs per job type' );
50 $this->addOption( 'list', 'Show a list of all jobs instead of counts' );
51 $this->addOption( 'type', 'Only show/count jobs of a given type', false, true );
52 $this->addOption( 'status', 'Filter list by state (unclaimed,delayed,claimed,abandoned)' );
53 $this->addOption( 'limit', 'Limit of jobs listed' );
54 }
55
56 public function execute() {
57 $typeFilter = $this->getOption( 'type', '' );
58 $stateFilter = $this->getOption( 'status', '' );
59 $stateLimit = (float)$this->getOption( 'limit', INF );
60
61 $group = MediaWikiServices::getInstance()->getJobQueueGroup();
62
63 $filteredTypes = $typeFilter
64 ? [ $typeFilter ]
65 : $group->getQueueTypes();
66 $filteredStates = $stateFilter
67 ? array_intersect_key( self::$stateMethods, [ $stateFilter => 1 ] )
69
70 if ( $this->hasOption( 'list' ) ) {
71 $count = 0;
72 foreach ( $filteredTypes as $type ) {
73 $queue = $group->get( $type );
74 foreach ( $filteredStates as $state => $method ) {
75 foreach ( $queue->$method() as $job ) {
77 $this->output( $job->toString() . " status=$state\n" );
78 if ( ++$count >= $stateLimit ) {
79 return;
80 }
81 }
82 }
83 }
84 } elseif ( $this->hasOption( 'group' ) ) {
85 foreach ( $filteredTypes as $type ) {
86 $queue = $group->get( $type );
87 $delayed = $queue->getDelayedCount();
88 $pending = $queue->getSize();
89 $claimed = $queue->getAcquiredCount();
90 $abandoned = $queue->getAbandonedCount();
91 $active = max( 0, $claimed - $abandoned );
92 if ( ( $pending + $claimed + $delayed + $abandoned ) > 0 ) {
93 $this->output(
94 "{$type}: $pending queued; " .
95 "$claimed claimed ($active active, $abandoned abandoned); " .
96 "$delayed delayed\n"
97 );
98 }
99 }
100 } else {
101 $count = 0;
102 foreach ( $filteredTypes as $type ) {
103 $count += $group->get( $type )->getSize();
104 }
105 $this->output( "$count\n" );
106 }
107 }
108}
109
110$maintClass = ShowJobs::class;
111require_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.
Maintenance script that reports the number of jobs currently waiting in the primary database.
Definition showJobs.php:38
execute()
Do the actual work.
Definition showJobs.php:56
__construct()
Default constructor.
Definition showJobs.php:46
static $stateMethods
Definition showJobs.php:39
if(count( $args)< 1) $job
$maintClass
Definition showJobs.php:110