MediaWiki  1.23.2
nextJobDB.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
31 class NextJobDB extends Maintenance {
32  public function __construct() {
33  parent::__construct();
34  $this->mDescription = "Pick a database that has pending jobs";
35  $this->addOption( 'type', "Search by job type", false, true );
36  $this->addOption( 'types', "Space separated list of job types to search for", false, true );
37  }
38 
39  public function execute() {
40  global $wgJobTypesExcludedFromDefaultQueue;
41 
42  // job type required/picked
43  if ( $this->hasOption( 'types' ) ) {
44  $types = explode( ' ', $this->getOption( 'types' ) );
45  } elseif ( $this->hasOption( 'type' ) ) {
46  $types = array( $this->getOption( 'type' ) );
47  } else {
48  $types = false;
49  }
50 
51  // Handle any required periodic queue maintenance
53 
54  // Get all the queues with jobs in them
55  $pendingDBs = JobQueueAggregator::singleton()->getAllReadyWikiQueues();
56  if ( !count( $pendingDBs ) ) {
57  return; // no DBs with jobs or cache is both empty and locked
58  }
59 
60  do {
61  $again = false;
62 
63  $candidates = array(); // list of (type, db)
64  // Flatten the tree of candidates into a flat list so that a random
65  // item can be selected, weighing each queue (type/db tuple) equally.
66  foreach ( $pendingDBs as $type => $dbs ) {
67  if (
68  ( is_array( $types ) && in_array( $type, $types ) ) ||
69  ( $types === false && !in_array( $type, $wgJobTypesExcludedFromDefaultQueue ) )
70  ) {
71  foreach ( $dbs as $db ) {
72  $candidates[] = array( $type, $db );
73  }
74  }
75  }
76  if ( !count( $candidates ) ) {
77  return; // no jobs for this type
78  }
79 
80  list( $type, $db ) = $candidates[mt_rand( 0, count( $candidates ) - 1 )];
81  } while ( $again );
82 
83  if ( $this->hasOption( 'types' ) ) {
84  $this->output( $db . " " . $type . "\n" );
85  } else {
86  $this->output( $db . "\n" );
87  }
88  }
89 
94  private function executeReadyPeriodicTasks() {
95  global $wgLocalDatabases, $wgMemc;
96 
97  $count = 0;
98  $memcKey = 'jobqueue:periodic:lasttime';
99  $timestamp = (int)$wgMemc->get( $memcKey ); // UNIX timestamp or 0
100  if ( ( time() - $timestamp ) > 300 || mt_rand( 0, 999 ) == 0 ) { // 5 minutes
101  if ( $wgMemc->add( "$memcKey:rebuild", 1, 1800 ) ) { // lock
102  foreach ( $wgLocalDatabases as $db ) {
103  $count += JobQueueGroup::singleton( $db )->executeReadyPeriodicTasks();
104  }
105  $wgMemc->set( $memcKey, time() );
106  $wgMemc->delete( "$memcKey:rebuild" ); // unlock
107  }
108  }
109 
110  return $count;
111  }
112 }
113 
114 $maintClass = "NextJobDb";
115 require_once RUN_MAINTENANCE_IF_MAIN;
NextJobDB\__construct
__construct()
Default constructor.
Definition: nextJobDB.php:32
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$maintClass
$maintClass
Definition: nextJobDB.php:114
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
NextJobDB\executeReadyPeriodicTasks
executeReadyPeriodicTasks()
Do all ready periodic jobs for all databases every 5 minutes (and .1% of the time)
Definition: nextJobDB.php:94
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
NextJobDB
Maintenance script that picks a database that has pending jobs.
Definition: nextJobDB.php:31
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$count
$count
Definition: UtfNormalTest2.php:96
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:61
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:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
JobQueueAggregator\singleton
static singleton()
Definition: JobQueueAggregator.php:44
NextJobDB\execute
execute()
Do the actual work.
Definition: nextJobDB.php:39
$type
$type
Definition: testCompression.php:46