| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Adds scheduling support to the Kestrun server. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This cmdlet allows you to register a scheduling service with the Kestrun server. |
| | | 6 | | It can be used to manage scheduled tasks and jobs in the context of the Kestrun server. |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance to which the scheduling service will be added. |
| | | 9 | | .PARAMETER MaxRunspaces |
| | | 10 | | The maximum number of runspaces to use for scheduling tasks. If not specified, defaults to 0 (unlimited). |
| | | 11 | | .PARAMETER PassThru |
| | | 12 | | If specified, the cmdlet will return the modified server instance after adding the scheduling service. |
| | | 13 | | .EXAMPLE |
| | | 14 | | $server | Add-KrScheduling -MaxRunspaces 5 |
| | | 15 | | This example adds scheduling support to the server, with a maximum of 5 runspaces. |
| | | 16 | | .EXAMPLE |
| | | 17 | | $server | Add-KrScheduling |
| | | 18 | | This example adds scheduling support to the server without specifying a maximum number of runspaces. |
| | | 19 | | .NOTES |
| | | 20 | | This cmdlet is used to register a scheduling service with the Kestrun server, allowing you to manage scheduled t |
| | | 21 | | #> |
| | | 22 | | function Add-KrScheduling { |
| | | 23 | | [KestrunRuntimeApi('Definition')] |
| | | 24 | | [CmdletBinding()] |
| | | 25 | | [OutputType([Kestrun.Hosting.KestrunHost])] |
| | | 26 | | param( |
| | | 27 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 28 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 29 | | |
| | | 30 | | [Parameter()] |
| | | 31 | | [int]$MaxRunspaces, |
| | | 32 | | |
| | | 33 | | [Parameter()] |
| | | 34 | | [switch]$PassThru |
| | | 35 | | ) |
| | | 36 | | begin { |
| | | 37 | | # Ensure the server instance is resolved |
| | 0 | 38 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 39 | | } |
| | | 40 | | process { |
| | 0 | 41 | | if ($MaxRunspaces -eq 0) { |
| | | 42 | | # If MaxRunspaces is 0, use the default configuration |
| | 0 | 43 | | $Server.AddScheduling() | Out-Null |
| | | 44 | | } else { |
| | 0 | 45 | | $Server.AddScheduling($MaxRunspaces) | Out-Null |
| | | 46 | | } |
| | | 47 | | |
| | 0 | 48 | | if ($PassThru.IsPresent) { |
| | | 49 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 50 | | return $Server |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |