Reputation: 2066
I have this as part of a script
$timeoutSeconds = $timeoutMinutes * 60
$job = Start-Job -ScriptBlock $block -ArgumentList @($environment, $filter)
Wait-Job $job -Timeout $timeoutSeconds
Stop-Job $job
Remove-Job $job
And I would like to raise an error (is part of an octopus deploy step) if it's timed out
Thanks
Upvotes: 4
Views: 748
Reputation: 411
How about something like this:
Wait-Job $job -Timeout $timeoutSeconds
if ($job.state -eq 'Running') {
Write-Error "Job timed out but did not complete."
}
$jobResults = Receive-Job $job
$jobResults
Stop-Job $job
Remove-Job $job
Upvotes: 5