Skip to content

Commit

Permalink
Merge pull request #1393 from Badgerati/schedule-error-handling
Browse files Browse the repository at this point in the history
Improves Error Handling in Schedules, Timers, Tasks, and Logging; Removes Global scope from TimerEvent; Adds functions for retrieving Schedule and Task Processes
  • Loading branch information
Badgerati authored Sep 15, 2024
2 parents 78aa711 + 91ae295 commit 9a99c96
Show file tree
Hide file tree
Showing 32 changed files with 850 additions and 296 deletions.
23 changes: 23 additions & 0 deletions docs/Tutorials/Schedules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 29 additions & 6 deletions docs/Tutorials/Tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -184,15 +184,38 @@ 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
Be careful if you choose to edit these objects, as they will affect the server.

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 |
10 changes: 5 additions & 5 deletions examples/Web-PagesKestrel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Start-PodeServer -Threads 2 -ListenerType Kestrel {
Add-PodeEndpoint -Address localhost -Port $Port -Protocol Http -Name '8081Address' -RedirectTo '8090Address'

# allow the local ip and some other ips
Add-PodeAccessRule -Access Allow -Type IP -Values @('127.0.0.1', '[::1]')
Add-PodeAccessRule -Access Allow -Type IP -Values @('192.169.0.1', '192.168.0.2')
# Add-PodeAccessRule -Access Allow -Type IP -Values @('127.0.0.1', '[::1]')
# Add-PodeAccessRule -Access Allow -Type IP -Values @('192.169.0.1', '192.168.0.2')

# deny an ip
Add-PodeAccessRule -Access Deny -Type IP -Values 10.10.10.10
Add-PodeAccessRule -Access Deny -Type IP -Values '10.10.0.0/24'
Add-PodeAccessRule -Access Deny -Type IP -Values all
# Add-PodeAccessRule -Access Deny -Type IP -Values 10.10.10.10
# Add-PodeAccessRule -Access Deny -Type IP -Values '10.10.0.0/24'
# Add-PodeAccessRule -Access Deny -Type IP -Values all

# log requests to the terminal
New-PodeLoggingMethod -Terminal -Batch 10 -BatchTimeout 10 | Enable-PodeRequestLogging
Expand Down
2 changes: 1 addition & 1 deletion pode.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Task IndexSamples {
# List of directories to exclude
$sampleMarkDownPath = './docs/Getting-Started/Samples.md'
$excludeDirs = @('scripts', 'views', 'static', 'public', 'assets', 'timers', 'modules',
'Authentication', 'certs', 'logs', 'relative', 'routes')
'Authentication', 'certs', 'logs', 'relative', 'routes', 'issues')

# Convert exlusion list into single regex pattern for directory matching
$dirSeparator = [IO.Path]::DirectorySeparatorChar
Expand Down
2 changes: 2 additions & 0 deletions src/Locales/ar/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'مدة Access-Control-Max-Age غير صالحة المقدمة: {0}. يجب أن تكون أكبر من 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'تعريف OpenAPI باسم {0} موجود بالفعل.'
renamePodeOADefinitionTagExceptionMessage = "لا يمكن استخدام Rename-PodeOADefinitionTag داخل Select-PodeOADefinition 'ScriptBlock'."
taskProcessDoesNotExistExceptionMessage = 'عملية المهمة غير موجودة: {0}'
scheduleProcessDoesNotExistExceptionMessage = 'عملية الجدول الزمني غير موجودة: {0}'
definitionTagChangeNotAllowedExceptionMessage = 'لا يمكن تغيير علامة التعريف لمسار.'
getRequestBodyNotAllowedExceptionMessage = 'لا يمكن أن تحتوي عمليات {0} على محتوى الطلب.'
}
2 changes: 2 additions & 0 deletions src/Locales/de/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Ungültige Access-Control-Max-Age-Dauer angegeben: {0}. Sollte größer als 0 sein.'
openApiDefinitionAlreadyExistsExceptionMessage = 'Die OpenAPI-Definition mit dem Namen {0} existiert bereits.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag kann nicht innerhalb eines 'ScriptBlock' von Select-PodeOADefinition verwendet werden."
taskProcessDoesNotExistExceptionMessage = "Der Aufgabenprozess '{0}' existiert nicht."
scheduleProcessDoesNotExistExceptionMessage = "Der Aufgabenplanerprozess '{0}' existiert nicht."
definitionTagChangeNotAllowedExceptionMessage = 'Definitionstag für eine Route kann nicht geändert werden.'
getRequestBodyNotAllowedExceptionMessage = '{0}-Operationen können keinen Anforderungstext haben.'
}
2 changes: 2 additions & 0 deletions src/Locales/en-us/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Invalid Access-Control-Max-Age duration supplied: {0}. Should be greater than 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'OpenAPI definition named {0} already exists.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag cannot be used inside a Select-PodeOADefinition 'ScriptBlock'."
taskProcessDoesNotExistExceptionMessage = 'Task process does not exist: {0}'
scheduleProcessDoesNotExistExceptionMessage = 'Schedule process does not exist: {0}'
definitionTagChangeNotAllowedExceptionMessage = 'Definition Tag for a Route cannot be changed.'
getRequestBodyNotAllowedExceptionMessage = '{0} operations cannot have a Request Body.'
}
5 changes: 3 additions & 2 deletions src/Locales/en/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Invalid Access-Control-Max-Age duration supplied: {0}. Should be greater than 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'OpenAPI definition named {0} already exists.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag cannot be used inside a Select-PodeOADefinition 'ScriptBlock'."
taskProcessDoesNotExistExceptionMessage = 'Task process does not exist: {0}'
scheduleProcessDoesNotExistExceptionMessage = 'Schedule process does not exist: {0}'
definitionTagChangeNotAllowedExceptionMessage = 'Definition Tag for a Route cannot be changed.'
getRequestBodyNotAllowedExceptionMessage = '{0} operations cannot have a Request Body.'
}

}
2 changes: 2 additions & 0 deletions src/Locales/es/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Duración inválida para Access-Control-Max-Age proporcionada: {0}. Debe ser mayor que 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'La definición de OpenAPI con el nombre {0} ya existe.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag no se puede usar dentro de un 'ScriptBlock' de Select-PodeOADefinition."
taskProcessDoesNotExistExceptionMessage = "El proceso de la tarea '{0}' no existe."
scheduleProcessDoesNotExistExceptionMessage = "El proceso del programación '{0}' no existe."
definitionTagChangeNotAllowedExceptionMessage = 'La etiqueta de definición para una Route no se puede cambiar.'
getRequestBodyNotAllowedExceptionMessage = 'Las operaciones {0} no pueden tener un cuerpo de solicitud.'
}
2 changes: 2 additions & 0 deletions src/Locales/fr/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Durée Access-Control-Max-Age invalide fournie : {0}. Doit être supérieure à 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'La définition OpenAPI nommée {0} existe déjà.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag ne peut pas être utilisé à l'intérieur d'un 'ScriptBlock' de Select-PodeOADefinition."
taskProcessDoesNotExistExceptionMessage = "Le processus de la tâche '{0}' n'existe pas."
scheduleProcessDoesNotExistExceptionMessage = "Le processus de l'horaire '{0}' n'existe pas."
definitionTagChangeNotAllowedExceptionMessage = 'Le tag de définition pour une Route ne peut pas être modifié.'
getRequestBodyNotAllowedExceptionMessage = 'Les opérations {0} ne peuvent pas avoir de corps de requête.'
}
Expand Down
2 changes: 2 additions & 0 deletions src/Locales/it/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Durata non valida fornita per Access-Control-Max-Age: {0}. Deve essere maggiore di 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'La definizione OpenAPI denominata {0} esiste già.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag non può essere utilizzato all'interno di un 'ScriptBlock' di Select-PodeOADefinition."
taskProcessDoesNotExistExceptionMessage = "Il processo dell'attività '{0}' non esiste."
scheduleProcessDoesNotExistExceptionMessage = "Il processo della programma '{0}' non esiste."
definitionTagChangeNotAllowedExceptionMessage = 'Il tag di definizione per una Route non può essere cambiato.'
getRequestBodyNotAllowedExceptionMessage = 'Le operazioni {0} non possono avere un corpo della richiesta.'
}
5 changes: 3 additions & 2 deletions src/Locales/ja/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = '無効な Access-Control-Max-Age 期間が提供されました:{0}。0 より大きくする必要があります。'
openApiDefinitionAlreadyExistsExceptionMessage = '名前が {0} の OpenAPI 定義は既に存在します。'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag は Select-PodeOADefinition 'ScriptBlock' 内で使用できません。"
taskProcessDoesNotExistExceptionMessage = 'タスクプロセスが存在しません: {0}'
scheduleProcessDoesNotExistExceptionMessage = 'スケジュールプロセスが存在しません: {0}'
definitionTagChangeNotAllowedExceptionMessage = 'Routeの定義タグは変更できません。'
getRequestBodyNotAllowedExceptionMessage = '{0}操作にはリクエストボディを含めることはできません。'
}

}
4 changes: 3 additions & 1 deletion src/Locales/ko/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = '잘못된 Access-Control-Max-Age 기간이 제공되었습니다: {0}. 0보다 커야 합니다.'
openApiDefinitionAlreadyExistsExceptionMessage = '이름이 {0}인 OpenAPI 정의가 이미 존재합니다.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag은 Select-PodeOADefinition 'ScriptBlock' 내에서 사용할 수 없습니다."
taskProcessDoesNotExistExceptionMessage = '작업 프로세스가 존재하지 않습니다: {0}'
scheduleProcessDoesNotExistExceptionMessage = '스케줄 프로세스가 존재하지 않습니다: {0}'
definitionTagChangeNotAllowedExceptionMessage = 'Route에 대한 정의 태그는 변경할 수 없습니다.'
getRequestBodyNotAllowedExceptionMessage = '{0} 작업에는 요청 본문이 있을 수 없습니다.'
}
}
5 changes: 3 additions & 2 deletions src/Locales/nl/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Ongeldige Access-Control-Max-Age duur opgegeven: {0}. Moet groter zijn dan 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'OpenAPI-definitie met de naam {0} bestaat al.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag kan niet worden gebruikt binnen een Select-PodeOADefinition 'ScriptBlock'."
taskProcessDoesNotExistExceptionMessage = "Taakproces '{0}' bestaat niet."
scheduleProcessDoesNotExistExceptionMessage = "Schema-proces '{0}' bestaat niet."
definitionTagChangeNotAllowedExceptionMessage = 'Definitietag voor een route kan niet worden gewijzigd.'
getRequestBodyNotAllowedExceptionMessage = '{0}-operaties kunnen geen Request Body hebben.'
}

}
5 changes: 3 additions & 2 deletions src/Locales/pl/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Podano nieprawidłowy czas trwania Access-Control-Max-Age: {0}. Powinien być większy niż 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'Definicja OpenAPI o nazwie {0} już istnieje.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag nie może być używany wewnątrz 'ScriptBlock' Select-PodeOADefinition."
taskProcessDoesNotExistExceptionMessage = "Proces zadania '{0}' nie istnieje."
scheduleProcessDoesNotExistExceptionMessage = "Proces harmonogramu '{0}' nie istnieje."
definitionTagChangeNotAllowedExceptionMessage = 'Tag definicji dla Route nie może zostać zmieniony.'
getRequestBodyNotAllowedExceptionMessage = 'Operacje {0} nie mogą mieć treści żądania.'
}

}
2 changes: 2 additions & 0 deletions src/Locales/pt/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = 'Duração inválida fornecida para Access-Control-Max-Age: {0}. Deve ser maior que 0.'
openApiDefinitionAlreadyExistsExceptionMessage = 'A definição OpenAPI com o nome {0} já existe.'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag não pode ser usado dentro de um 'ScriptBlock' Select-PodeOADefinition."
taskProcessDoesNotExistExceptionMessage = "O processo da tarefa '{0}' não existe."
scheduleProcessDoesNotExistExceptionMessage = "O processo do cronograma '{0}' não existe."
definitionTagChangeNotAllowedExceptionMessage = 'A Tag de definição para uma Route não pode ser alterada.'
getRequestBodyNotAllowedExceptionMessage = 'As operações {0} não podem ter um corpo de solicitação.'
}
2 changes: 2 additions & 0 deletions src/Locales/zh/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
invalidAccessControlMaxAgeDurationExceptionMessage = '提供的 Access-Control-Max-Age 时长无效:{0}。应大于 0。'
openApiDefinitionAlreadyExistsExceptionMessage = '名为 {0} 的 OpenAPI 定义已存在。'
renamePodeOADefinitionTagExceptionMessage = "Rename-PodeOADefinitionTag 不能在 Select-PodeOADefinition 'ScriptBlock' 内使用。"
taskProcessDoesNotExistExceptionMessage = "任务进程 '{0}' 不存在。"
scheduleProcessDoesNotExistExceptionMessage = "计划进程 '{0}' 不存在。"
definitionTagChangeNotAllowedExceptionMessage = 'Route的定义标签无法更改。'
getRequestBodyNotAllowedExceptionMessage = '{0} 操作不能包含请求体。'
}
3 changes: 3 additions & 0 deletions src/Pode.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
'ConvertFrom-PodeXml',
'Set-PodeDefaultFolder',
'Get-PodeDefaultFolder',
'Invoke-PodeGC',

# routes
'Add-PodeRoute',
Expand Down Expand Up @@ -184,6 +185,7 @@
'Use-PodeSchedules',
'Test-PodeSchedule',
'Clear-PodeSchedules',
'Get-PodeScheduleProcess',

# timers
'Add-PodeTimer',
Expand All @@ -207,6 +209,7 @@
'Close-PodeTask',
'Test-PodeTaskCompleted',
'Wait-PodeTask',
'Get-PodeTaskProcess',

# middleware
'Add-PodeMiddleware',
Expand Down
Loading

0 comments on commit 9a99c96

Please sign in to comment.