From 1ca32de90364b4efe977e9b9f18efb0868ecda13 Mon Sep 17 00:00:00 2001 From: Patrick Veilleux Date: Mon, 26 Jun 2023 12:49:43 -0400 Subject: [PATCH] add auto-retry on steamcmd errors --- functions/server/Update-Server.psm1 | 17 ++++++++++++++++- global.psm1 | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/functions/server/Update-Server.psm1 b/functions/server/Update-Server.psm1 index 6d32a6d..0d45385 100644 --- a/functions/server/Update-Server.psm1 +++ b/functions/server/Update-Server.psm1 @@ -56,7 +56,22 @@ function Update-Server { #Run the update String Write-ServerMsg "$UpdateType $ValidatingString $VersionString Build." try { - $Task = Start-Process $Global.SteamCMD -ArgumentList "+runscript `"$ScriptPath`"" -Wait -PassThru -NoNewWindow + $ExitCode = -1 + $Retries = 0 + while ($ExitCode -ne 0 -and $Retries -lt $Global.MaxDownloadRetries) { + $Task = Start-Process $Global.SteamCMD -ArgumentList "+runscript `"$ScriptPath`"" -Wait -PassThru -NoNewWindow + $ExitCode = $Task.ExitCode + if ($ExitCode -ne 0) { + Write-ServerMsg "SteamCMD failed to complete. Retrying..." + $Retries++ + } + else { + Write-ServerMsg "SteamCMD completed successfully." + } + } + if ($Retries -eq $Global.MaxDownloadRetries) { + Exit-WithError -ErrorMsg "SteamCMD failed to complete after $Global.MaxDownloadRetries retries." + } } catch { Exit-WithError -ErrorMsg "SteamCMD failed to complete." diff --git a/global.psm1 b/global.psm1 index 77e04e2..66a001a 100644 --- a/global.psm1 +++ b/global.psm1 @@ -46,6 +46,9 @@ $GlobalDetails = @{ #Lock Timeout in miuntes LockTimeout = 10 + + #Max download retries + MaxDownloadRetries = 5 } #Create the object