| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Starts a previously created task by id. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Transitions the task from Created state to Running. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance. |
| | | 8 | | .PARAMETER Id |
| | | 9 | | Task id to start. |
| | | 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 | | Start-KrTask -Id 'task-id' |
| | | 16 | | Starts the specified task. |
| | | 17 | | .NOTES |
| | | 18 | | Requires the Kestrun Task service to be added to the server via Add-KrTasksService. |
| | | 19 | | Returns $true if the task was found and started; $false if the task was not found or could not be started. |
| | | 20 | | A task can only be started once; subsequent attempts to start a task will return $false. |
| | | 21 | | Starting a task is asynchronous; the task will run in the background after being started. |
| | | 22 | | Use Get-KrTask or Get-KrTaskState to monitor the task state. |
| | | 23 | | #> |
| | | 24 | | function Start-KrTask { |
| | | 25 | | [KestrunRuntimeApi('Everywhere')] |
| | | 26 | | [CmdletBinding(SupportsShouldProcess)] |
| | | 27 | | [OutputType([bool])] |
| | | 28 | | param( |
| | | 29 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 30 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 31 | | |
| | | 32 | | [Parameter(Mandatory)] |
| | | 33 | | [string]$Id |
| | | 34 | | ) |
| | | 35 | | begin { |
| | 0 | 36 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 37 | | } |
| | | 38 | | process { |
| | 0 | 39 | | if ($PSCmdlet.ShouldProcess("Task $Id", 'Start')) { |
| | 0 | 40 | | return $Server.Tasks.Start($Id) |
| | | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |