Skip to content

Wait-SpectreJobs

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

EXAMPLE 1

Invoke-SpectreCommandWithProgress -ScriptBlock {
    param (
        $Context
    )
    $jobs = @()
    $jobs += Add-SpectreJob -Context $Context -JobName "job 1" -Job (Start-Job { Start-Sleep -Seconds 2 })
    $jobs += Add-SpectreJob -Context $Context -JobName "job 2" -Job (Start-Job { Start-Sleep -Seconds 4 })
    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

EstimatedDurationSeconds

The estimated duration of the jobs in seconds. This is used to calculate the progress of the jobs if the job progress is not available.

TypeRequiredPositionPipelineInput
[Int32]false4false

Syntax

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