From a1a3b7fcf7bcf976b4b1848d3ac4e0661dade4dd Mon Sep 17 00:00:00 2001 From: Igor Wulff Date: Tue, 30 Apr 2024 13:24:25 +0200 Subject: [PATCH] Added retry mechanic for flushing Redis Cache --- src/Step/Deploy/PreDeploy/CleanRedisCache.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Step/Deploy/PreDeploy/CleanRedisCache.php b/src/Step/Deploy/PreDeploy/CleanRedisCache.php index b2f45e5e9..d538e3eff 100644 --- a/src/Step/Deploy/PreDeploy/CleanRedisCache.php +++ b/src/Step/Deploy/PreDeploy/CleanRedisCache.php @@ -87,11 +87,20 @@ public function execute(): void !empty($redisConfig['password']) ? (string)$redisConfig['password'] : null ); - try { - $client->connect(); - $client->flushDb(); - } catch (CredisException $e) { - throw new StepException($e->getMessage(), Error::DEPLOY_REDIS_CACHE_CLEAN_FAILED, $e); + $maxRetries = 3; + for ($attempt = 0; $attempt <= $maxRetries; $attempt++) { + try { + $client->connect(); + $client->flushDb(); + break; + } catch (CredisException $e) { + if ($attempt === $maxRetries) { + throw new StepException($e->getMessage(), + Error::DEPLOY_REDIS_CACHE_CLEAN_FAILED, $e); + } + $this->logger->info('Clearing redis cache failed. Retrying in 10 seconds...'); + sleep(10); + } } } }