Skip to content

Migrate REST API progress status to use Write-Progress #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ function Wait-JobWithAnimation
$animationFrames = '|','/','-','\'
$framesPerSecond = 9

# We'll wrap the description (if provided) in brackets for display purposes.
if ($Description -ne "")
{
$Description = "[$Description]"
}

$progressId = 1
$iteration = 0
[int] $seconds = 0
$secondWord = 'seconds'

while ($runningJobs.Count -gt 0)
{
# We'll run into issues if we try to modify the same collection we're iterating over
Expand Down Expand Up @@ -92,24 +90,45 @@ function Wait-JobWithAnimation
$runingJobs.Clear()
}

Write-InteractiveHost "`r$($animationFrames[$($iteration % $($animationFrames.Length))]) Elapsed: $([int]($iteration / $framesPerSecond)) second(s) $Description" -NoNewline -f Yellow
Start-Sleep -Milliseconds ([int](1000/$framesPerSecond))
$seconds = [int]($iteration / $framesPerSecond)
$secondWord = 'seconds'
if (1 -eq $seconds)
{
$secondWord = 'second'
}

$animationFrameNumber = $iteration % $($animationFrames.Length)
$progressParams = @{
'Activity' = $Description
'Status' = "$($animationFrames[$animationFrameNumber]) Elapsed: $seconds $secondWord"
'PercentComplete' = $(($animationFrameNumber / $animationFrames.Length) * 100)
'Id' = $progressId
}

Write-Progress @progressParams
Start-Sleep -Milliseconds ([int](1000 / $framesPerSecond))
$iteration++
}

# We'll wrap the description (if provided) in brackets for display purposes.
if (-not [string]::IsNullOrWhiteSpace($Description))
{
$Description = "[$Description]"
}

if ($allJobsCompleted)
{
Write-InteractiveHost "`rDONE - Operation took $([int]($iteration / $framesPerSecond)) second(s) $Description" -NoNewline -f Green
Write-InteractiveHost "`rDONE - Operation took $seconds $secondWord $Description" -NoNewline -f Green

# We forcibly set Verbose to false here since we don't need it printed to the screen, since we just did above -- we just need to log it.
Write-Log -Message "DONE - Operation took $([int]($iteration / $framesPerSecond)) second(s) $Description" -Level Verbose -Verbose:$false
Write-Log -Message "DONE - Operation took $seconds $secondWord $Description" -Level Verbose -Verbose:$false
}
else
{
Write-InteractiveHost "`rDONE (FAILED) - Operation took $([int]($iteration / $framesPerSecond)) second(s) $Description" -NoNewline -f Red
Write-InteractiveHost "`rDONE (FAILED) - Operation took $seconds $secondWord $Description" -NoNewline -f Red

# We forcibly set Verbose to false here since we don't need it printed to the screen, since we just did above -- we just need to log it.
Write-Log -Message "DONE (FAILED) - Operation took $([int]($iteration / $framesPerSecond)) second(s) $Description" -Level Verbose -Verbose:$false
Write-Log -Message "DONE (FAILED) - Operation took $seconds $secondWord $Description" -Level Verbose -Verbose:$false
}

Write-InteractiveHost ""
Expand Down