Merge pull request #7457 from nextcloud/enh/6878/pull-3-times

DockeractionManager: rewrite `PullImage` function to re-try 3 times before failing
This commit is contained in:
Simon L. 2026-01-22 12:11:27 +01:00 committed by GitHub
commit 9e3acb9f68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -503,14 +503,24 @@ readonly class DockerActionManager {
} catch (\Throwable $e) {
$imageIsThere = false;
}
try {
$this->guzzleClient->post($url);
} catch (RequestException $e) {
$message = "Could not pull image " . $imageName . ": " . $e->getResponse()?->getBody()->getContents();
if ($imageIsThere === false) {
throw new \Exception($message);
} else {
error_log($message);
$maxRetries = 3;
for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {
try {
$this->guzzleClient->post($url);
break;
} catch (RequestException $e) {
$message = "Could not pull image " . $imageName . " (attempt $attempt/$maxRetries): " . $e->getResponse()?->getBody()->getContents();
if ($attempt === $maxRetries) {
if ($imageIsThere === false) {
throw new \Exception($message);
} else {
error_log($message);
}
} else {
error_log($message . ' Retrying...');
sleep(1);
}
}
}
}