MediaWiki  master
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
31 class ManageJobs extends Maintenance {
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Perform administrative tasks on a job queue' );
35  $this->addOption( 'type', 'Job type', true, true );
36  $this->addOption( 'action', 'Queue operation ("delete", "repush-abandoned")', true, true );
37  }
39  public function execute() {
40  $type = $this->getOption( 'type' );
41  $action = $this->getOption( 'action' );
43  $group = JobQueueGroup::singleton();
44  $queue = $group->get( $type );
46  if ( $action === 'delete' ) {
47  $this->delete( $queue );
48  } elseif ( $action === 'repush-abandoned' ) {
49  $this->repushAbandoned( $queue );
50  } else {
51  $this->fatalError( "Invalid action '$action'." );
52  }
53  }
55  private function delete( JobQueue $queue ) {
56  $this->output( "Queue has {$queue->getSize()} job(s); deleting...\n" );
57  $queue->delete();
58  $this->output( "Done; current size is {$queue->getSize()} job(s).\n" );
59  }
61  private function repushAbandoned( JobQueue $queue ) {
63  $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getDomain(), $queue->getType() );
65  $now = wfTimestampNow();
66  $lastRepushTime = $cache->get( $key );
67  if ( $lastRepushTime === false ) {
68  $lastRepushTime = wfTimestamp( TS_MW, 1 ); // include all jobs
69  }
71  $this->output( "Last re-push time: $lastRepushTime; current time: $now\n" );
73  $count = 0;
74  $skipped = 0;
75  foreach ( $queue->getAllAbandonedJobs() as $job ) {
77  if ( $job->getQueuedTimestamp() < wfTimestamp( TS_UNIX, $lastRepushTime ) ) {
78  ++$skipped;
79  continue; // already re-pushed in prior round
80  }
82  $queue->push( $job );
83  ++$count;
85  if ( ( $count % $this->getBatchSize() ) == 0 ) {
86  $queue->waitForBackups();
87  }
88  }
90  $cache->set( $key, $now ); // next run will ignore these jobs
92  $this->output( "Re-pushed $count job(s) [$skipped skipped].\n" );
93  }
94 }
97 require_once RUN_MAINTENANCE_IF_MAIN;
getOption( $name, $default=null)
Get an option, or return the default.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
static getInstance( $id)
Get a cached instance of the specified type of cache object.
Definition: ObjectCache.php:92
Definition: manageJobs.php:96
Definition: maintenance.txt:50
Maintenance script that handles managing job queue admin tasks (re-push, delete, ...)
Definition: manageJobs.php:31
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
addDescription( $text)
Set the description text.
Convenience function; returns MediaWiki timestamp for the present time.
Definition: mcc.php:33
output( $out, $channel=null)
Throw some output to the user.
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
repushAbandoned(JobQueue $queue)
Definition: manageJobs.php:61
push( $jobs, $flags=0)
Push one or more jobs into the queue.
Definition: JobQueue.php:310
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
Class to handle enqueueing and running of background jobs.
Definition: JobQueue.php:31
if(count( $args)< 1) $job
Returns batch size.
Definition: JobQueue.php:122
Get an iterator to traverse over all abandoned jobs in this queue.
Definition: JobQueue.php:630
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static singleton( $domain=false)
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Wait for any replica DBs or backup servers to catch up.
Definition: JobQueue.php:560
const CACHE_DB
Definition: Defines.php:99