MediaWiki REL1_33
copyJobQueue.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription( 'Copy jobs from one queue system to another.' );
38 $this->addOption( 'src', 'Key to $wgJobQueueMigrationConfig for source', true, true );
39 $this->addOption( 'dst', 'Key to $wgJobQueueMigrationConfig for destination', true, true );
40 $this->addOption( 'type', 'Types of jobs to copy (use "all" for all)', true, true );
41 $this->setBatchSize( 500 );
42 }
43
44 public function execute() {
46
47 $srcKey = $this->getOption( 'src' );
48 $dstKey = $this->getOption( 'dst' );
49
50 if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) {
51 $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$srcKey'." );
52 } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) {
53 $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$dstKey'." );
54 }
55
56 $types = ( $this->getOption( 'type' ) === 'all' )
57 ? JobQueueGroup::singleton()->getQueueTypes()
58 : [ $this->getOption( 'type' ) ];
59
60 foreach ( $types as $type ) {
61 $baseConfig = [ 'type' => $type, 'wiki' => wfWikiID() ];
62 $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] );
63 $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] );
64
65 list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() );
66 $this->output( "Copied $totalOK/$total queued $type jobs.\n" );
67
68 list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() );
69 $this->output( "Copied $totalOK/$total delayed $type jobs.\n" );
70 }
71 }
72
73 protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) {
74 $total = 0;
75 $totalOK = 0;
76 $batch = [];
77 foreach ( $jobs as $job ) {
78 ++$total;
79 $batch[] = $job;
80 if ( count( $batch ) >= $this->getBatchSize() ) {
81 $dst->push( $batch );
82 $totalOK += count( $batch );
83 $batch = [];
84 $dst->waitForBackups();
85 }
86 }
87 if ( count( $batch ) ) {
88 $dst->push( $batch );
89 $totalOK += count( $batch );
90 $dst->waitForBackups();
91 }
92
93 return [ $total, $totalOK ];
94 }
95}
96
97$maintClass = CopyJobQueue::class;
98require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Copy all jobs from one job queue system to another.
execute()
Do the actual work.
copyJobs(JobQueue $src, JobQueue $dst, $jobs)
__construct()
Default constructor.
Class to handle enqueueing and running of background jobs.
Definition JobQueue.php:31
push( $jobs, $flags=0)
Push one or more jobs into the queue.
Definition JobQueue.php:310
static factory(array $params)
Get a job queue object of the specified type.
Definition JobQueue.php:106
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
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.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$maintClass
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
$batch
Definition linkcache.txt:23
require_once RUN_MAINTENANCE_IF_MAIN
if(count( $args)< 1) $job