proxb / PoshRSJob

Provides an alternative to PSjobs with greater performance and less overhead to run commands in the background, freeing up the console and allowing throttling on the jobs.
MIT License
542 stars 87 forks source link

Wait-RSJob -ShowProgress: -Completed & -Activity (as in Write-Progress) #165

Closed flolilo closed 6 years ago

flolilo commented 7 years ago

Do you want to request a feature or report a bug? Feature.

What is the current behavior? $foobar | Start-RSJob -Name "XYZ" -ScriptBlock {$_ = $_ + 1} | | Wait-RSJob -ShowProgress will show a progress-bar similarly to Write-Progress -Activity "RSJobs Tracker" -Status "Remaining Jobs: $($_.Length - $current_RSJob_index)" -Percentcomplete (($_.Length * 100) / $current_RSJob_index). The progress-bar will stay on the console after completion.

What is the expected behavior?

Which versions of Powershell and which OS are affected by this issue? Did this work in previous versions of our scripts? Win10 (1703) x64, PowerShell v5.1

Please provide a code example showing the issue, if applicable:

[int]$ThreadCount = 4
[array]$Files_In = Get-ChildItem -Path .\ -File | ForEach-Object {
    [PSCustomObject]@{
        FullName = $_.FullName
        Hash = $null
    }
}
while($true){
    foreach($i in $Files_In.FullName){
        Write-Output $i
    }
    $Files_In | Start-RSJob -Name "GetHash" -Throttle $ThreadCount -ScriptBlock {
        $_.Hash = Get-FileHash -LiteralPath $_.FullName -Algorithm SHA1 | Select-Object -ExpandProperty Hash
    } | Wait-RSJob -ShowProgress | Receive-RSJob

    foreach($i in $Files_In.Hash){
        Write-Output $i
    }
    Start-Sleep -Seconds 1
}
MVKozlov commented 7 years ago

In my case Progress do not stay on console after completion but I'm agree, -Completed should be added after waiting cycle

But about names ... if Jobs count require progress bar, the progress bar can not accommodate all the names :) especially if your example runned in C:\windows\system32

flolilo commented 7 years ago

For me, the behavior is quite inconsitent - with the above script, most of the time, the progress-bar will vanish, but especially in larger scripts, they tend to stick somewhere in the upper lines of the console.

grafik Here is a quick example - the script that spawned it is long completed, as is the RSJob.

Concerning the names: I can understand that and I admit that this is no big issue at all. However, it would be nice if one could state what the script is waiting for. With all the progress-bar-debris it's quite easy to get confused which Wait-RSJob-"iteration" is waiting at the moment, which makes troubleshooting...well, not impossible but just a tad more difficult. ;-) But again, I suppose there are more pressing concerns than an unnamed progress-bar. ;-)

flolilo commented 6 years ago

Manually updated my PoshRSJob? installation to e454b56 - looking good now! Thanks!