| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Gets the status or result of a task by id. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Without -Detailed returns task state; with -Detailed returns TaskResult snapshot. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance. |
| | | 8 | | .PARAMETER Id |
| | | 9 | | Task id to query. |
| | | 10 | | .PARAMETER State |
| | | 11 | | When present, return only the task state string. |
| | | 12 | | .EXAMPLE |
| | | 13 | | Get-KrTask -Id 'task-id' |
| | | 14 | | |
| | | 15 | | Returns the current state of the specified task. |
| | | 16 | | .EXAMPLE |
| | | 17 | | Get-KrTask -Id 'task-id' -Detailed |
| | | 18 | | Returns the detailed result of the specified task. |
| | | 19 | | .EXAMPLE |
| | | 20 | | Get-KrTask |
| | | 21 | | |
| | | 22 | | Returns a list of all tasks with their current states. |
| | | 23 | | .OUTPUTS |
| | | 24 | | When -Detailed is specified, returns a [Kestrun.Tasks.TaskResult] object; otherwise returns a string with the task s |
| | | 25 | | When Id is not specified, returns an array of [Kestrun.Tasks.TaskResult] objects for all tasks. |
| | | 26 | | #> |
| | | 27 | | function Get-KrTask { |
| | | 28 | | [KestrunRuntimeApi('Everywhere')] |
| | | 29 | | [CmdletBinding(defaultParameterSetName = 'Default')] |
| | | 30 | | [OutputType([Kestrun.Tasks.KrTask[]])] |
| | | 31 | | [OutputType([Kestrun.Tasks.KrTask])] |
| | | 32 | | param( |
| | | 33 | | [Parameter(ValueFromPipeline = $true)] |
| | | 34 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 35 | | |
| | | 36 | | [Parameter()] |
| | | 37 | | [string]$Id, |
| | | 38 | | |
| | | 39 | | [Parameter(parameterSetName = 'State')] |
| | | 40 | | [switch]$State |
| | | 41 | | ) |
| | | 42 | | begin { |
| | 0 | 43 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 44 | | } |
| | | 45 | | process { |
| | 0 | 46 | | if ([string]::IsNullOrEmpty($Id)) { |
| | 0 | 47 | | return $Server.Tasks.List() |
| | | 48 | | } |
| | 0 | 49 | | if ($State.IsPresent) { |
| | 0 | 50 | | return $Server.Tasks.GetState($Id) |
| | | 51 | | } else { |
| | 0 | 52 | | return $Server.Tasks.Get($Id) |
| | | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |