Skip to content

Wait-SpectreJobs

Synopsis

Waits for Spectre jobs to complete.


Description

This function waits for Spectre jobs to complete by checking the progress of each job and updating the corresponding task value. Adapted from https://key2consulting.com/powershell-how-to-display-job-progress/


Examples

Waits for two jobs to complete

Invoke-SpectreCommandWithProgress -Title "Waiting" -ScriptBlock {
    param (
        $Context
    )
    $jobs = @()
    $jobs += Add-SpectreJob -Context $Context -JobName "job 1" -Job (Start-Job { Start-Sleep -Seconds 5 })
    $jobs += Add-SpectreJob -Context $Context -JobName "job 2" -Job (Start-Job { Start-Sleep -Seconds 10 })
    Wait-SpectreJobs -Context $Context -Jobs $jobs
}

Parameters

Context

The Spectre progress context object. https://spectreconsole.net/api/spectre.console/progresscontext/

TypeRequiredPositionPipelineInput
[Object]true1false

Jobs

An array of Spectre jobs which are decorated PowerShell jobs.

TypeRequiredPositionPipelineInput
[Array]true2false

TimeoutSeconds

The maximum number of seconds to wait for the jobs to complete. Defaults to 60 seconds.

TypeRequiredPositionPipelineInput
[Int32]false3false

Syntax

Wait-SpectreJobs [-Context] <Object> [-Jobs] <Array> [[-TimeoutSeconds] <Int32>] [<CommonParameters>]