MediaWiki  1.29.1
showJobs.php
Go to the documentation of this file.
1 <?php
28 require_once __DIR__ . '/Maintenance.php';
29 
36 class ShowJobs extends Maintenance {
37  protected static $stateMethods = [
38  'unclaimed' => 'getAllQueuedJobs',
39  'delayed' => 'getAllDelayedJobs',
40  'claimed' => 'getAllAcquiredJobs',
41  'abandoned' => 'getAllAbandonedJobs',
42  ];
43 
44  public function __construct() {
45  parent::__construct();
46  $this->addDescription( 'Show number of jobs waiting in master database' );
47  $this->addOption( 'group', 'Show number of jobs per job type' );
48  $this->addOption( 'list', 'Show a list of all jobs instead of counts' );
49  $this->addOption( 'type', 'Only show/count jobs of a given type', false, true );
50  $this->addOption( 'status', 'Filter list by state (unclaimed,delayed,claimed,abandoned)' );
51  $this->addOption( 'limit', 'Limit of jobs listed' );
52  }
53 
54  public function execute() {
55  $typeFilter = $this->getOption( 'type', '' );
56  $stateFilter = $this->getOption( 'status', '' );
57  $stateLimit = (float)$this->getOption( 'limit', INF );
58 
59  $group = JobQueueGroup::singleton();
60 
61  $filteredTypes = $typeFilter
62  ? [ $typeFilter ]
63  : $group->getQueueTypes();
64  $filteredStates = $stateFilter
65  ? array_intersect_key( self::$stateMethods, [ $stateFilter => 1 ] )
67 
68  if ( $this->hasOption( 'list' ) ) {
69  $count = 0;
70  foreach ( $filteredTypes as $type ) {
71  $queue = $group->get( $type );
72  foreach ( $filteredStates as $state => $method ) {
73  foreach ( $queue->$method() as $job ) {
75  $this->output( $job->toString() . " status=$state\n" );
76  if ( ++$count >= $stateLimit ) {
77  return;
78  }
79  }
80  }
81  }
82  } elseif ( $this->hasOption( 'group' ) ) {
83  foreach ( $filteredTypes as $type ) {
84  $queue = $group->get( $type );
85  $delayed = $queue->getDelayedCount();
86  $pending = $queue->getSize();
87  $claimed = $queue->getAcquiredCount();
88  $abandoned = $queue->getAbandonedCount();
89  $active = max( 0, $claimed - $abandoned );
90  if ( ( $pending + $claimed + $delayed + $abandoned ) > 0 ) {
91  $this->output(
92  "{$type}: $pending queued; " .
93  "$claimed claimed ($active active, $abandoned abandoned); " .
94  "$delayed delayed\n"
95  );
96  }
97  }
98  } else {
99  $count = 0;
100  foreach ( $filteredTypes as $type ) {
101  $count += $group->get( $type )->getSize();
102  }
103  $this->output( "$count\n" );
104  }
105  }
106 }
107 
108 $maintClass = "ShowJobs";
109 require_once RUN_MAINTENANCE_IF_MAIN;
ShowJobs\__construct
__construct()
Default constructor.
Definition: showJobs.php:44
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$maintClass
$maintClass
Definition: showJobs.php:108
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$type
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ShowJobs\execute
execute()
Do the actual work.
Definition: showJobs.php:54
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
$queue
$queue
Definition: mergeMessageFileList.php:161
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:47
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:71
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:236
ShowJobs
Maintenance script that reports the number of jobs currently waiting in master database.
Definition: showJobs.php:36
ShowJobs\$stateMethods
static $stateMethods
Definition: showJobs.php:37