2013-04-09 07:01:32 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copy all jobs from one job queue system to another.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-23 20:44:38 +00:00
|
|
|
use MediaWiki\WikiMap\WikiMap;
|
2022-01-27 20:19:18 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2013-04-09 07:01:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copy all jobs from one job queue system to another.
|
|
|
|
|
* This uses an ad-hoc $wgJobQueueMigrationConfig setting,
|
|
|
|
|
* which is a map of queue system names to JobQueue::factory() parameters.
|
|
|
|
|
* The parameters should not have wiki or type settings and thus partial.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
class CopyJobQueue extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Copy jobs from one queue system to another.' );
|
2013-04-09 07:01:32 +00:00
|
|
|
$this->addOption( 'src', 'Key to $wgJobQueueMigrationConfig for source', true, true );
|
|
|
|
|
$this->addOption( 'dst', 'Key to $wgJobQueueMigrationConfig for destination', true, true );
|
|
|
|
|
$this->addOption( 'type', 'Types of jobs to copy (use "all" for all)', true, true );
|
|
|
|
|
$this->setBatchSize( 500 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
global $wgJobQueueMigrationConfig;
|
|
|
|
|
|
|
|
|
|
$srcKey = $this->getOption( 'src' );
|
|
|
|
|
$dstKey = $this->getOption( 'dst' );
|
|
|
|
|
|
|
|
|
|
if ( !isset( $wgJobQueueMigrationConfig[$srcKey] ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "\$wgJobQueueMigrationConfig not set for '$srcKey'." );
|
2013-04-09 07:01:32 +00:00
|
|
|
} elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "\$wgJobQueueMigrationConfig not set for '$dstKey'." );
|
2013-04-09 07:01:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$types = ( $this->getOption( 'type' ) === 'all' )
|
2023-08-31 09:21:12 +00:00
|
|
|
? $this->getServiceContainer()->getJobQueueGroup()->getQueueTypes()
|
2016-02-17 09:09:32 +00:00
|
|
|
: [ $this->getOption( 'type' ) ];
|
2013-04-09 07:01:32 +00:00
|
|
|
|
2019-07-04 08:28:18 +00:00
|
|
|
$dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
|
2013-04-09 07:01:32 +00:00
|
|
|
foreach ( $types as $type ) {
|
2019-07-04 08:28:18 +00:00
|
|
|
$baseConfig = [ 'type' => $type, 'domain' => $dbDomain ];
|
2013-04-09 07:01:32 +00:00
|
|
|
$src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] );
|
|
|
|
|
$dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] );
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $total, $totalOK ] = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() );
|
2013-04-09 07:01:32 +00:00
|
|
|
$this->output( "Copied $totalOK/$total queued $type jobs.\n" );
|
|
|
|
|
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $total, $totalOK ] = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() );
|
2013-04-09 07:01:32 +00:00
|
|
|
$this->output( "Copied $totalOK/$total delayed $type jobs.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) {
|
|
|
|
|
$total = 0;
|
|
|
|
|
$totalOK = 0;
|
2016-02-17 09:09:32 +00:00
|
|
|
$batch = [];
|
2013-04-09 07:01:32 +00:00
|
|
|
foreach ( $jobs as $job ) {
|
|
|
|
|
++$total;
|
|
|
|
|
$batch[] = $job;
|
2017-11-05 08:09:51 +00:00
|
|
|
if ( count( $batch ) >= $this->getBatchSize() ) {
|
2014-04-16 17:51:11 +00:00
|
|
|
$dst->push( $batch );
|
|
|
|
|
$totalOK += count( $batch );
|
2016-02-17 09:09:32 +00:00
|
|
|
$batch = [];
|
2013-04-09 07:01:32 +00:00
|
|
|
$dst->waitForBackups();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( count( $batch ) ) {
|
2014-04-16 17:51:11 +00:00
|
|
|
$dst->push( $batch );
|
|
|
|
|
$totalOK += count( $batch );
|
2013-04-09 07:01:32 +00:00
|
|
|
$dst->waitForBackups();
|
|
|
|
|
}
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $total, $totalOK ];
|
2013-04-09 07:01:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CopyJobQueue::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|