0) { Log::info('SSH operation succeeded after retry', array_merge($context, [ 'attempt' => $attempt + 1, ])); } return $result; } catch (\Throwable $e) { $lastError = $e; $lastErrorMessage = $e->getMessage(); // Check if it's retryable and not the last attempt if ($this->isRetryableSshError($lastErrorMessage) && $attempt < $maxRetries - 1) { $delay = $this->calculateRetryDelay($attempt); // Add deployment log if available (for ExecuteRemoteCommand trait) if (isset($this->application_deployment_queue) && method_exists($this, 'addRetryLogEntry')) { $this->addRetryLogEntry($attempt + 1, $maxRetries, $delay, $lastErrorMessage); } sleep($delay); continue; } // Not retryable or max retries reached break; } } // All retries exhausted if ($attempt >= $maxRetries) { Log::error('SSH operation failed after all retries', array_merge($context, [ 'attempts' => $attempt, 'error' => $lastErrorMessage, ])); } if ($throwError && $lastError) { throw $lastError; } return null; } }