1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-20 11:41:08 +01:00

If repository mirroring fails, keep trying the other mirrors

Summary: Ref T4338. Currently, if you have several mirrors and the first one fails, we won't try the other mirrors (since we'll throw and that will take us out of the mirroring process). Instead, try each mirror even if one fails, and then throw an AggregateException with all the failures.

Test Plan:
  - Ran `bin/repository mirror` normally.
  - Faked an exception, ran again, got the AggregateException I expected.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4338

Differential Revision: https://secure.phabricator.com/D8067
This commit is contained in:
epriestley 2014-01-25 14:02:09 -08:00
parent dd944f7d83
commit 31e11a97d2

View file

@ -18,6 +18,28 @@ final class PhabricatorRepositoryMirrorEngine
->withRepositoryPHIDs(array($repository->getPHID()))
->execute();
$exceptions = array();
foreach ($mirrors as $mirror) {
try {
$this->pushRepositoryToMirror($repository, $mirror);
} catch (Exception $ex) {
$exceptions[] = $ex;
}
}
if ($exceptions) {
throw new PhutilAggregateException(
pht(
'Exceptions occurred while mirroring the "%s" repository.',
$repository->getCallsign()),
$exceptions);
}
}
private function pushRepositoryToMirror(
PhabricatorRepository $repository,
PhabricatorRepositoryMirror $mirror) {
// TODO: This is a little bit janky, but we don't have first-class
// infrastructure for running remote commands against an arbitrary remote
// right now. Just make an emphemeral copy of the repository and muck with
@ -28,14 +50,13 @@ final class PhabricatorRepositoryMirrorEngine
$proxy->makeEphemeral();
$proxy->setDetail('hosting-enabled', false);
foreach ($mirrors as $mirror) {
$proxy->setDetail('remote-uri', $mirror->getRemoteURI());
$proxy->setCredentialPHID($mirror->getCredentialPHID());
$this->log(pht('Pushing to remote "%s"...', $mirror->getRemoteURI()));
if (!$proxy->isGit()) {
throw new Exception('Unsupported VCS!');
throw new Exception(pht('Unsupported VCS!'));
}
$future = $proxy->getRemoteCommandFuture(
@ -46,6 +67,5 @@ final class PhabricatorRepositoryMirrorEngine
->setCWD($proxy->getLocalPath())
->resolvex();
}
}
}