|
13 | 13 |
|
14 | 14 | In the wider flow of a Runspace Workflow, one Worker's Output Queue is alse another Worker's Input Queue. |
15 | 15 | Thus we create a chain of workers from original input to finished output, each step individually with as many runspaces as needed. |
| 16 | +
|
| 17 | + Note: Worker Versions |
| 18 | + There are different runtime versions for the Runspace Workers. |
| 19 | + They affect features available, performance, and - possibly - bugs. |
| 20 | + Older (lower) versions are more tested, but some features are only available with later versions. |
| 21 | + If you encounter an issue with any of the later versions, that works on an older one, please file a bug report and provide as much information as possible. |
| 22 | +
|
| 23 | + Versions and their features: |
| 24 | + 1: Baseline |
| 25 | + 2: Added RetryCount, RetryCondition, Timeout, TimeoutType parameters, as well as support for overriding settings per-item with New-PSFRsWorkItem |
16 | 26 | |
17 | 27 | .PARAMETER Name |
18 | 28 | Name of the worker. |
|
104 | 114 | .PARAMETER SessionState |
105 | 115 | A fully prepared session state object to use when creating the worker runspaces. |
106 | 116 | Be aware that if your session state does not contain basic language tools, the background runspace will likely fail. |
| 117 | +
|
| 118 | + .PARAMETER Timeout |
| 119 | + How long each individual item may run before timing out. |
| 120 | + Note: This parameter forces a V2 worker or later (see description). |
| 121 | +
|
| 122 | + .PARAMETER TimeoutType |
| 123 | + What kind of timeout processing we perform. |
| 124 | + - Start: Time from the start of the current item. |
| 125 | + - Idle: Time since last activity |
| 126 | + Last Activity is measured by the last Write-PSFMessage or Reset-PSFRsAgentInactivity call. |
| 127 | + Note: This parameter forces a V2 worker or later (see description). |
| 128 | +
|
| 129 | + .PARAMETER RetryCount |
| 130 | + How many times to try again if processing an object fails. |
| 131 | + Note: This parameter forces a V2 worker or later (see description). |
| 132 | +
|
| 133 | + .PARAMETER RetryCondition |
| 134 | + If an object fails and retries are configured, only retries are attempted for cases where this condition is true. |
| 135 | + This scriptblock has access to two variables: |
| 136 | + - $_: The Error that happened |
| 137 | + - $this: The object currently being processed |
| 138 | + It is executed in the context of the runspace where the issue happend (so modules and commands are available, but the direct scope of the execution code is not.) |
| 139 | + Note: This parameter forces a V2 worker or later (see description). |
| 140 | +
|
| 141 | + .PARAMETER WorkerVersion |
| 142 | + What version of worker to create. |
| 143 | + Later versions offer more features, older versions more stability. |
107 | 144 | |
108 | 145 | .PARAMETER WorkflowName |
109 | 146 | Name of the Runspace Workflow this worker belongs to. |
|
191 | 228 | [initialsessionstate] |
192 | 229 | $SessionState, |
193 | 230 |
|
| 231 | + [PSFTimeSpanParameter] |
| 232 | + $Timeout, |
| 233 | + |
| 234 | + [PSFramework.Runspace.RSTimeout] |
| 235 | + $TimeoutType = 'Start', |
| 236 | + |
| 237 | + [int] |
| 238 | + $RetryCount, |
| 239 | + |
| 240 | + [PsfScriptBlock] |
| 241 | + $RetryCondition, |
| 242 | + |
| 243 | + [ValidateSet(1,2)] |
| 244 | + [int] |
| 245 | + $WorkerVersion, |
| 246 | + |
194 | 247 | [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] |
195 | 248 | [PsfArgumentCompleter('PSFramework-runspace-workflow-name')] |
196 | 249 | [string[]] |
|
202 | 255 | ) |
203 | 256 |
|
204 | 257 | begin { |
| 258 | + $versionMap = @{ |
| 259 | + 2 = @('Timeout', 'RetryCount', 'RetryCondition') |
| 260 | + } |
| 261 | + $useVersion = 1 |
| 262 | + |
| 263 | + foreach ($version in $versionMap.Keys | Sort-Object) { |
| 264 | + foreach ($parameterName in $versionMap[$version]) { |
| 265 | + if ($PSBoundParameters.ContainsKey($parameterName)) { |
| 266 | + $useVersion = $version |
| 267 | + } |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + if ($WorkerVersion) { |
| 272 | + if ($WorkerVersion -lt $useVersion) { |
| 273 | + Stop-PSFFunction -String 'Add-PSFRunspaceWorker.Error.VersionTooLow' -StringValues $WorkerVersion, $useVersion -EnableException $true -Cmdlet $PSCmdlet -Category InvalidArgument |
| 274 | + } |
| 275 | + $useVersion = $WorkerVersion |
| 276 | + } |
| 277 | + |
205 | 278 | $functionsResolved = @{ } |
206 | 279 |
|
207 | 280 | if (-not $Functions) { return } |
|
227 | 300 |
|
228 | 301 | foreach ($resolvedWorkflow in $resolvedWorkflows) { |
229 | 302 | $worker = $resolvedWorkflow.AddWorker($Name, $InQueue, $OutQueue, $ScriptBlock, $Count) |
| 303 | + $worker.WorkerVersion = $useVersion |
230 | 304 |
|
231 | 305 | if ($Begin) { $worker.Begin = $Begin } |
232 | 306 | if ($End) { $worker.End = $End } |
233 | 307 | if ($MaxItems) { $worker.MaxItems = $MaxItems } |
234 | 308 | if ($CloseOutQueue) { $worker.CloseOutQueue = $true } |
235 | 309 | if ($QueuesToClose) { $worker.QueuesToClose = $QueuesToClose } |
| 310 | + if ($Timeout) { |
| 311 | + $worker.Timeout = $Timeout |
| 312 | + $worker.TimeoutType = $TimeoutType |
| 313 | + } |
| 314 | + if ($RetryCount) { $worker.RetryCount = $RetryCount } |
| 315 | + if ($RetryCondition) { $worker.RetryCondition = $RetryCondition } |
236 | 316 |
|
237 | 317 | if ($SessionState) { $worker.SessionState = $SessionState } |
238 | 318 | foreach ($module in $Modules) { $worker.Modules.Add($module) } |
|
0 commit comments