addDescription( 'Copy jobs from one queue system to another.' ); $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] ) ) { $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$srcKey'." ); } elseif ( !isset( $wgJobQueueMigrationConfig[$dstKey] ) ) { $this->fatalError( "\$wgJobQueueMigrationConfig not set for '$dstKey'." ); } $types = ( $this->getOption( 'type' ) === 'all' ) ? JobQueueGroup::singleton()->getQueueTypes() : [ $this->getOption( 'type' ) ]; foreach ( $types as $type ) { $baseConfig = [ 'type' => $type, 'wiki' => wfWikiID() ]; $src = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$srcKey] ); $dst = JobQueue::factory( $baseConfig + $wgJobQueueMigrationConfig[$dstKey] ); list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllQueuedJobs() ); $this->output( "Copied $totalOK/$total queued $type jobs.\n" ); list( $total, $totalOK ) = $this->copyJobs( $src, $dst, $src->getAllDelayedJobs() ); $this->output( "Copied $totalOK/$total delayed $type jobs.\n" ); } } protected function copyJobs( JobQueue $src, JobQueue $dst, $jobs ) { $total = 0; $totalOK = 0; $batch = []; foreach ( $jobs as $job ) { ++$total; $batch[] = $job; if ( count( $batch ) >= $this->getBatchSize() ) { $dst->push( $batch ); $totalOK += count( $batch ); $batch = []; $dst->waitForBackups(); } } if ( count( $batch ) ) { $dst->push( $batch ); $totalOK += count( $batch ); $dst->waitForBackups(); } return [ $total, $totalOK ]; } } $maintClass = CopyJobQueue::class; require_once RUN_MAINTENANCE_IF_MAIN;