From 91ae29508c6f8e171163b2b6eda7af580fa033f3 Mon Sep 17 00:00:00 2001 From: Matthew Kelly Date: Sat, 14 Sep 2024 18:40:53 +0100 Subject: [PATCH] Clean-up, and adds quick schedule/task process docs --- docs/Tutorials/Schedules.md | 23 +++++++++++++++++++++++ docs/Tutorials/Tasks.md | 35 +++++++++++++++++++++++++++++------ src/Locales/de/Pode.psd1 | 2 +- src/Private/Context.ps1 | 5 ----- src/Private/Tasks.ps1 | 2 +- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/docs/Tutorials/Schedules.md b/docs/Tutorials/Schedules.md index 9c754bfb1..2665501d0 100644 --- a/docs/Tutorials/Schedules.md +++ b/docs/Tutorials/Schedules.md @@ -126,6 +126,29 @@ Get-PodeSchedule -Name Name1 Get-PodeSchedule -Name Name1, Name2 ``` +## Getting Schedule Processes + +You can retrieve a list of processes triggered by Schedules via [`Get-PodeScheduleProcess`](../../Functions/Schedules/Get-PodeScheduleProcess) - this will return processes created either by a Schedule's natural time-based trigger, or via [`Invoke-PodeSchedule`](../../Functions/Schedules/Invoke-PodeSchedule). + +You can either retrieve all processes, or filter them by Schedule Name, or Process ID/Status: + +```powershell +# retrieves all schedule processes +Get-PodeScheduleProcess + +# retrieves all schedule processes for the "ScheduleName" process +Get-PodeScheduleProcess -Name 'ScheduleName' + +# retrieves the schedule process with ID "ScheduleId" +Get-PodeScheduleProcess -Id 'ScheduleId' + +# retrieves all running schedule processes +Get-PodeScheduleProcess -State 'Running' + +# retrieves all pending schedule processes for "ScheduleName" +Get-PodeScheduleProcess -Name 'ScheduleName' -State 'Running' +``` + ## Next Trigger Time When you retrieve a Schedule using [`Get-PodeSchedule`](../../Functions/Schedules/Get-PodeSchedule), each Schedule object will already have its next trigger time as `NextTriggerTime`. However, if you want to get a trigger time further ino the future than this, then you can use the [`Get-PodeScheduleNextTrigger`](../../Functions/Schedules/Get-PodeScheduleNextTrigger) function. diff --git a/docs/Tutorials/Tasks.md b/docs/Tutorials/Tasks.md index ac257a98c..f6a98e339 100644 --- a/docs/Tutorials/Tasks.md +++ b/docs/Tutorials/Tasks.md @@ -51,7 +51,7 @@ Add-PodeTask -Name 'Example' -ArgumentList @{ Name = 'Rick'; Environment = 'Mult } ``` -Tasks parameters **must** be bound in the param block in order to be used, but the values for the paramters can be set through the `-ArgumentList` hashtable parameter in either the Add-PodeTask definition or when invoking the task. The following snippet would populate the parameters to the task with the same values as the above example but the `-ArgumentList` parameter is populated during invocation. Note that Keys in the `-ArgumentList` hashtable parameter set during invocation override the same Keys set during task creation: +Tasks parameters **must** be bound in the param block in order to be used, but the values for the paramters can be set through the `-ArgumentList` hashtable parameter in either the Add-PodeTask definition or when invoking the task. The following snippet would populate the parameters to the task with the same values as the above example but the `-ArgumentList` parameter is populated during invocation. Note that Keys in the `-ArgumentList` hashtable parameter set during invocation override the same Keys set during task creation: ```powershell Add-PodeTask -Name 'Example' -ScriptBlock { @@ -184,6 +184,29 @@ Get-PodeTask -Name Example1 Get-PodeTask -Name Example1, Example2 ``` +## Getting Task Processes + +You can retrieve a list of processes triggered by Tasks via [`Get-PodeTaskProcess`](../../Functions/Tasks/Get-PodeTaskProcess) - this will return processes created via [`Invoke-PodeTask`](../../Functions/Tasks/Invoke-PodeTask). + +You can either retrieve all processes, or filter them by Task Name, or Process ID/Status: + +```powershell +# retrieves all task processes +Get-PodeTaskProcess + +# retrieves all task processes for the "TaskName" process +Get-PodeTaskProcess -Name 'TaskName' + +# retrieves the task process with ID "TaskId" +Get-PodeTaskProcess -Id 'TaskId' + +# retrieves all running task processes +Get-PodeTaskProcess -State 'Running' + +# retrieves all pending task processes for "TaskName" +Get-PodeTaskProcess -Name 'TaskName' -State 'Running' +``` + ## Task Object !!! warning @@ -191,8 +214,8 @@ Get-PodeTask -Name Example1, Example2 The following is the structure of the Task object internally, as well as the object that is returned from [`Get-PodeTask`](../../Functions/Tasks/Get-PodeTask): -| Name | Type | Description | -| ---- | ---- | ----------- | -| Name | string | The name of the Task | -| Script | scriptblock | The scriptblock of the Task | -| Arguments | hashtable | The arguments supplied from ArgumentList | +| Name | Type | Description | +| --------- | ----------- | ---------------------------------------- | +| Name | string | The name of the Task | +| Script | scriptblock | The scriptblock of the Task | +| Arguments | hashtable | The arguments supplied from ArgumentList | diff --git a/src/Locales/de/Pode.psd1 b/src/Locales/de/Pode.psd1 index c250afe73..8fe33f3f0 100644 --- a/src/Locales/de/Pode.psd1 +++ b/src/Locales/de/Pode.psd1 @@ -211,7 +211,7 @@ viewsFolderNameAlreadyExistsExceptionMessage = 'Der Name des Ansichtsordners existiert bereits: {0}' noNameForWebSocketResetExceptionMessage = 'Kein Name für das Zurücksetzen des WebSocket angegeben.' mergeDefaultAuthNotInListExceptionMessage = "Die MergeDefault-Authentifizierung '{0}' befindet sich nicht in der angegebenen Authentifizierungsliste." - descriptionRequiredExceptionMessage = 'Eine Beschreibung ist erforderlich.' + descriptionRequiredExceptionMessage = 'Eine Beschreibung ist erforderlich für Pfad:{0} Antwort:{1}' pageNameShouldBeAlphaNumericExceptionMessage = 'Der Seitenname sollte einen gültigen alphanumerischen Wert haben: {0}' defaultValueNotBooleanOrEnumExceptionMessage = 'Der Standardwert ist kein Boolean und gehört nicht zum Enum.' openApiComponentSchemaDoesNotExistExceptionMessage = 'Das OpenApi-Komponentenschema {0} existiert nicht.' diff --git a/src/Private/Context.ps1 b/src/Private/Context.ps1 index 7667d73c0..28584fa42 100644 --- a/src/Private/Context.ps1 +++ b/src/Private/Context.ps1 @@ -526,16 +526,11 @@ function New-PodeRunspacePool { # setup main runspace pool $threadsCounts = @{ Default = 3 - # Timer = 1 Log = 1 Schedule = 1 Misc = 1 } - # if (!(Test-PodeTimersExist)) { - # $threadsCounts.Timer = 0 - # } - if (!(Test-PodeSchedulesExist)) { $threadsCounts.Schedule = 0 } diff --git a/src/Private/Tasks.ps1 b/src/Private/Tasks.ps1 index ae1f778cb..db596544e 100644 --- a/src/Private/Tasks.ps1 +++ b/src/Private/Tasks.ps1 @@ -169,7 +169,7 @@ function Get-PodeTaskScriptBlock { # build the script arguments $TaskEvent = @{ Lockable = $PodeContext.Threading.Lockables.Global - Sender = $Task + Sender = $task Timestamp = [DateTime]::UtcNow Metadata = @{} }