| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Returns a snapshot of the current schedule. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function retrieves the current schedule snapshot, including all scheduled jobs and their next run times. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun host object containing the scheduler. |
| | | 8 | | .PARAMETER Name |
| | | 9 | | Optional job name filter. If specified, only jobs matching the name will be returned. |
| | | 10 | | .PARAMETER TimeZoneId |
| | | 11 | | Optional Windows / IANA time-zone id to convert timestamps. |
| | | 12 | | Example: "Pacific Standard Time" or "Europe/Berlin" |
| | | 13 | | .PARAMETER AsHashtable |
| | | 14 | | If set, returns a hashtable instead of a ScheduleReport object. |
| | | 15 | | .EXAMPLE |
| | | 16 | | Get-KrScheduleSnapshot -Server $myServer |
| | | 17 | | Retrieves the schedule snapshot from the specified Kestrun server. |
| | | 18 | | .EXAMPLE |
| | | 19 | | Get-KrScheduleSnapshot -Server $myServer -Name 'Cache' |
| | | 20 | | Retrieves the schedule snapshot for the job named 'Cache'. |
| | | 21 | | .EXAMPLE |
| | | 22 | | Get-KrScheduleSnapshot -Server $myServer -TimeZoneId "Europe/Berlin" |
| | | 23 | | Retrieves the schedule snapshot with timestamps converted to the specified time zone. |
| | | 24 | | .EXAMPLE |
| | | 25 | | Get-KrScheduleSnapshot -Name 'ps-*' -TimeZoneId 'Pacific Standard Time' |
| | | 26 | | Retrieves all jobs matching the pattern 'ps-*' with timestamps converted to Pacific Standard Time. |
| | | 27 | | .OUTPUTS |
| | | 28 | | Returns a ScheduleReport object or a hashtable if AsHashtable is set. |
| | | 29 | | #> |
| | | 30 | | function Get-KrScheduleSnapshot { |
| | | 31 | | [KestrunRuntimeApi('Everywhere')] |
| | | 32 | | [CmdletBinding()] |
| | | 33 | | [OutputType([Kestrun.Scheduling.JobInfo[]])] |
| | | 34 | | [OutputType([Hashtable])] |
| | | 35 | | param( |
| | | 36 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 37 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 38 | | [string[]]$Name, |
| | | 39 | | [string]$TimeZoneId, |
| | | 40 | | [switch]$AsHashtable |
| | | 41 | | ) |
| | | 42 | | begin { |
| | | 43 | | # Ensure the server instance is resolved |
| | 0 | 44 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 45 | | } |
| | | 46 | | process { |
| | 0 | 47 | | $jobs = $Server.Scheduler.GetSnapshot() |
| | | 48 | | |
| | 0 | 49 | | if (-not $AsHashtable) { |
| | 0 | 50 | | return $jobs # strongly-typed JobInfo records |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | # PowerShell-friendly shape |
| | 0 | 54 | | return $jobs | ForEach-Object { |
| | 0 | 55 | | [ordered]@{ |
| | 0 | 56 | | Name = $_.Name |
| | 0 | 57 | | LastRunAt = $_.LastRunAt |
| | 0 | 58 | | NextRunAt = $_.NextRunAt |
| | 0 | 59 | | IsSuspended = $_.IsSuspended |
| | | 60 | | } |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | $tz = if ($TimeZoneId) { |
| | 0 | 64 | | [TimeZoneInfo]::FindSystemTimeZoneById($TimeZoneId) |
| | 0 | 65 | | } else { [TimeZoneInfo]::Utc } |
| | | 66 | | |
| | 0 | 67 | | $Server.Scheduler.GetSnapshot($tz, $AsHashtable, $Name) |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | |