Add --sleep option to refreshImageMetadata.php

For running long-term maintenance scripts, having waitForReplication()
is not enough as that method doesn't count for cross DC-replication and
replication the cloud making issues if kept running more than a couple
of hours. This mitigate the aforementioned problem.

Change-Id: Ifa0b31dde4a57a4d3f2b00c29410be568cfa6b91
This commit is contained in:
Amir Sarabadani 2021-06-29 21:06:39 +02:00
parent d86e6e0426
commit 128e55a5db

View file

@ -101,6 +101,12 @@ class RefreshImageMetadata extends Maintenance {
false,
true
);
$this->addOption(
'sleep',
'Time to sleep between each batch (in seconds). Default: 0',
false,
true
);
}
public function execute() {
@ -109,6 +115,7 @@ class RefreshImageMetadata extends Maintenance {
$verbose = $this->hasOption( 'verbose' );
$start = $this->getOption( 'start', false );
$split = $this->hasOption( 'split' );
$sleep = (int)$this->getOption( 'sleep', 0 );
$reserialize = $this->hasOption( 'convert-to-json' );
$upgraded = 0;
@ -182,6 +189,9 @@ class RefreshImageMetadata extends Maintenance {
}
$conds2 = [ 'img_name > ' . $dbw->addQuotes( $row->img_name ) ];
$lbFactory->waitForReplication();
if ( $sleep ) {
sleep( $sleep );
}
} while ( $res->numRows() === $batchSize );
$total = $upgraded + $leftAlone;