MediaWiki REL1_30
manageJobs.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
31class 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 }
38
39 public function execute() {
40 $type = $this->getOption( 'type' );
41 $action = $this->getOption( 'action' );
42
43 $group = JobQueueGroup::singleton();
44 $queue = $group->get( $type );
45
46 if ( $action === 'delete' ) {
47 $this->delete( $queue );
48 } elseif ( $action === 'repush-abandoned' ) {
49 $this->repushAbandoned( $queue );
50 } else {
51 $this->error( "Invalid action '$action'.", 1 );
52 }
53 }
54
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 }
60
61 private function repushAbandoned( JobQueue $queue ) {
62 $cache = ObjectCache::getInstance( CACHE_DB );
63 $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getWiki(), $queue->getType() );
64
65 $now = wfTimestampNow();
66 $lastRepushTime = $cache->get( $key );
67 if ( $lastRepushTime === false ) {
68 $lastRepushTime = wfTimestamp( TS_MW, 1 ); // include all jobs
69 }
70
71 $this->output( "Last re-push time: $lastRepushTime; current time: $now\n" );
72
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 }
81
82 $queue->push( $job );
83 ++$count;
84
85 if ( ( $count % $this->mBatchSize ) == 0 ) {
86 $queue->waitForBackups();
87 }
88 }
89
90 $cache->set( $key, $now ); // next run will ignore these jobs
91
92 $this->output( "Re-pushed $count job(s) [$skipped skipped].\n" );
93 }
94}
95
96$maintClass = "ManageJobs";
97require_once RUN_MAINTENANCE_IF_MAIN;
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static singleton( $wiki=false)
Class to handle enqueueing and running of background jobs.
Definition JobQueue.php:31
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
Maintenance script that handles managing job queue admin tasks (re-push, delete, ....
repushAbandoned(JobQueue $queue)
execute()
Do the actual work.
__construct()
Default constructor.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
const CACHE_DB
Definition Defines.php:104
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
$cache
Definition mcc.php:33
if(count( $args)< 1) $job