| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Removes a finished task from the registry. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Deletes a task after it has completed/faulted/cancelled; does not cancel. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance. |
| | | 8 | | .PARAMETER Id |
| | | 9 | | Task id to remove. |
| | | 10 | | .PARAMETER WhatIf |
| | | 11 | | Shows what would happen if the cmdlet runs. The cmdlet is not run. |
| | | 12 | | .PARAMETER Confirm |
| | | 13 | | Prompts you for confirmation before running the cmdlet. |
| | | 14 | | .EXAMPLE |
| | | 15 | | Remove-KrTask -Id 'task-id' |
| | | 16 | | Removes the specified task. |
| | | 17 | | .NOTES |
| | | 18 | | Requires the Kestrun Task service to be added to the server via Add-KrTasksService. |
| | | 19 | | A task can only be removed if it is in a final state (Completed, Failed, Stopped). |
| | | 20 | | Returns $true if the task was found and removed; $false if the task was not found or could not be removed. |
| | | 21 | | This cmdlet supports ShouldProcess for confirmation prompts. |
| | | 22 | | #> |
| | | 23 | | function Remove-KrTask { |
| | | 24 | | [KestrunRuntimeApi('Everywhere')] |
| | | 25 | | [CmdletBinding(SupportsShouldProcess)] |
| | | 26 | | [OutputType([bool])] |
| | | 27 | | param( |
| | | 28 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 29 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 30 | | |
| | | 31 | | [Parameter(Mandatory)] |
| | | 32 | | [string]$Id |
| | | 33 | | ) |
| | | 34 | | begin { |
| | 0 | 35 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 36 | | } |
| | | 37 | | process { |
| | 0 | 38 | | if ($PSCmdlet.ShouldProcess("Task $Id", 'Remove')) { |
| | 0 | 39 | | return $Server.Tasks.Remove($Id) |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | } |