Skip to content

Commit

Permalink
(nexus-repository-migrator) Adds Longer Timeout to AttemptMigration
Browse files Browse the repository at this point in the history
The post-migration launch process can take significantly longer than normal, due to the additional work Nexus is doing.

This change adds a configurable timeout to the Wait-NexusAvailability command, and uses it in the Nexus-Repository-Migrator package to increase the timeout from 3 minutes to 15.
  • Loading branch information
JPRuskin committed Sep 5, 2024
1 parent 67b9cbf commit 91e91ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ foreach ($Service in Get-NexusRepositoryServiceInstall) {
try {
Write-Host "Restarting '$($Service.ServiceName)'"
Restart-Service $Service.ServiceName
Wait-NexusAvailability -Hostname $Hostname -Config $NexusConfigFile -ErrorAction Stop
# The post-migration launch can take significantly longer than normal
Wait-NexusAvailability -Hostname $Hostname -Config $NexusConfigFile -Timeout 15 -ErrorAction Stop
} catch {
Write-Error -Message (@(
"The Nexus service '$($Service.ServiceName)' was restarted, but did not recover."
Expand Down
11 changes: 8 additions & 3 deletions automatic/nexus-repository/tools/helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ function Get-NexusUri {

function Wait-NexusAvailability {
param(
# The hostname in use
[Parameter()]
[string]$Hostname,

# The path to the config file
[Parameter(Mandatory)]
[Alias("Config")]
[string]$NexusConfigFile = (Join-Path $env:ProgramData "\sonatype-work\nexus3\etc\nexus.properties")
[string]$NexusConfigFile = (Join-Path $env:ProgramData "\sonatype-work\nexus3\etc\nexus.properties"),

# Configurable timeout in minutes
[uint16]$Timeout = 3
)
# As the service is started, this should be present momentarily
$Timer = [System.Diagnostics.Stopwatch]::StartNew()
Expand All @@ -148,7 +153,7 @@ function Wait-NexusAvailability {
$NexusUri = Get-NexusUri -Hostname $Hostname

Write-Host "Waiting on Nexus Web UI to be available at '$($NexusUri)'"
while ($Response.StatusCode -ne '200' -and $Timer.Elapsed.TotalMinutes -lt 3) {
while ($Response.StatusCode -ne '200' -and $Timer.Elapsed.TotalMinutes -lt $Timeout) {
try {
$Response = Invoke-WebRequest -Uri $NexusUri -UseBasicParsing
} catch {
Expand All @@ -160,7 +165,7 @@ function Wait-NexusAvailability {
if ($Response.StatusCode -eq '200') {
Write-Host "Nexus is ready!"
} else {
Write-Error "Nexus did not respond to requests at '$($NexusUri)' within 3 minutes of the service being started."
Write-Error "Nexus did not respond to requests at '$($NexusUri)' within $($Timeout) minutes of the service being started."
}
}

Expand Down

0 comments on commit 91e91ec

Please sign in to comment.