Skip to content

Commit ccc8393

Browse files
Merge pull request #731 from PowershellFrameworkCollective/completion-memory
1.14.449
2 parents 98c283d + 9710e67 commit ccc8393

32 files changed

Lines changed: 1418 additions & 119 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ PSFramework/PSFramework.psproj
1919
TestResults/*
2020

2121
# ignore the publishing Directory
22-
publish/*
22+
publish/*
23+
24+
# Ignore local test files (should be migrated to pester tests anyway)
25+
localTests/*

PSFramework/PSFramework.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSFramework.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '1.14.441'
7+
ModuleVersion = '1.14.449'
88

99
# ID used to uniquely identify this module
1010
GUID = '8028b914-132b-431f-baa9-94a6952f21ff'
@@ -144,6 +144,7 @@
144144
'Remove-PSFTempItem'
145145
'Remove-PSFTeppCompletion'
146146
'Reset-PSFConfig'
147+
'Reset-PSFRsAgentInactivity'
147148
'Resolve-PSFDefaultParameterValue'
148149
'Resolve-PSFItem'
149150
'Resolve-PSFPath'

PSFramework/bin/PSFramework.dll

3 KB
Binary file not shown.

PSFramework/bin/PSFramework.pdb

8 KB
Binary file not shown.

PSFramework/bin/PSFramework.xml

Lines changed: 178 additions & 4 deletions
Large diffs are not rendered by default.

PSFramework/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# CHANGELOG
22

3+
## 1.14.449 (2026-06-12)
4+
5+
- New: Configuration PSFramework.Message.LogErrorStack - When calling Write-PSFMessage and also specifying an ErrorRecord, should the ErrorRecord location of the error be used, rather than from where Write-PSFMessage was called?
6+
- New: Reset-PSFRsAgentInactivity - Signals the current Runspace Workflow Worker Agent is active.
7+
- Upd: Write-PSFMessage - added parameter `-ErrorStack` - logs the stacktrace of the error record provided, rather than its own call.
8+
- Upd: Add-PSFRunspaceWorker - added new generation of runspace workers, with a c#-based orchestration infrastructure,
9+
- Upd: Add-PSFRunspaceWorker - added option to retry failed input (including an optional condition logic on when to retry)
10+
- Upd: Add-PSFRunspaceWorker - added option to include per-item timeout (total time or idle time)
11+
- Upd: Set-PSFDynamicContentObject - add `-Cache` parameter, generating a DCO implementing a PSFramework cache (same as returned by New-PSFCache)
12+
- Fix: New-PSFCache - the cache object does not correctly remove objects
13+
314
## 1.14.441 (2026-06-03)
415

516
- Fix: New-PSFCache - timer only removes one expired item at a time

PSFramework/en-us/PSFramework.dll-Help.xml

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.

PSFramework/en-us/stringsRunspaces.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@{
22
'Add-PSFRunspaceWorker.Error.UntrustedFunctionCode' = 'Failed to load function {0}: The provided function code is not trusted (in Constrained language Mode) and cannot be imported. Ensure the code building the scriptblock is trusted to create a non-constrained scriptblock.' # $pair.Key
33
'Add-PSFRunspaceWorker.Error.UntrustedTextFunction' = 'Failed to load function {0}: String-based code is not trusted in a secured console. Provide its code as a scriptblock, rather than a string to enable code trust verification.' # $pair.Key
4+
'Add-PSFRunspaceWorker.Error.VersionTooLow' = 'Invalid Runspace Worker Version specified! Version specified: {0} | Minimum Version required for the selected parameters: {1}' # $WorkerVersion, $useVersion
45

56
'Invoke-PSFRunspace.Error.ModuleImport' = 'Failed to include module: "{0}"' # $module
67
'Invoke-PSFRunspace.Error.UntrustedTextFunction' = 'Failed to import function "{0}". Providing function-code as text is not supported in a hardened PowerShell process. Provide the function-code instead as a scriptblock.' # $pair.Key

PSFramework/functions/runspace/Add-PSFRunspaceWorker.ps1

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
1414
In the wider flow of a Runspace Workflow, one Worker's Output Queue is alse another Worker's Input Queue.
1515
Thus we create a chain of workers from original input to finished output, each step individually with as many runspaces as needed.
16+
17+
Note: Worker Versions
18+
There are different runtime versions for the Runspace Workers.
19+
They affect features available, performance, and - possibly - bugs.
20+
Older (lower) versions are more tested, but some features are only available with later versions.
21+
If you encounter an issue with any of the later versions, that works on an older one, please file a bug report and provide as much information as possible.
22+
23+
Versions and their features:
24+
1: Baseline
25+
2: Added RetryCount, RetryCondition, Timeout, TimeoutType parameters, as well as support for overriding settings per-item with New-PSFRsWorkItem
1626
1727
.PARAMETER Name
1828
Name of the worker.
@@ -104,6 +114,33 @@
104114
.PARAMETER SessionState
105115
A fully prepared session state object to use when creating the worker runspaces.
106116
Be aware that if your session state does not contain basic language tools, the background runspace will likely fail.
117+
118+
.PARAMETER Timeout
119+
How long each individual item may run before timing out.
120+
Note: This parameter forces a V2 worker or later (see description).
121+
122+
.PARAMETER TimeoutType
123+
What kind of timeout processing we perform.
124+
- Start: Time from the start of the current item.
125+
- Idle: Time since last activity
126+
Last Activity is measured by the last Write-PSFMessage or Reset-PSFRsAgentInactivity call.
127+
Note: This parameter forces a V2 worker or later (see description).
128+
129+
.PARAMETER RetryCount
130+
How many times to try again if processing an object fails.
131+
Note: This parameter forces a V2 worker or later (see description).
132+
133+
.PARAMETER RetryCondition
134+
If an object fails and retries are configured, only retries are attempted for cases where this condition is true.
135+
This scriptblock has access to two variables:
136+
- $_: The Error that happened
137+
- $this: The object currently being processed
138+
It is executed in the context of the runspace where the issue happend (so modules and commands are available, but the direct scope of the execution code is not.)
139+
Note: This parameter forces a V2 worker or later (see description).
140+
141+
.PARAMETER WorkerVersion
142+
What version of worker to create.
143+
Later versions offer more features, older versions more stability.
107144
108145
.PARAMETER WorkflowName
109146
Name of the Runspace Workflow this worker belongs to.
@@ -191,6 +228,22 @@
191228
[initialsessionstate]
192229
$SessionState,
193230

231+
[PSFTimeSpanParameter]
232+
$Timeout,
233+
234+
[PSFramework.Runspace.RSTimeout]
235+
$TimeoutType = 'Start',
236+
237+
[int]
238+
$RetryCount,
239+
240+
[PsfScriptBlock]
241+
$RetryCondition,
242+
243+
[ValidateSet(1,2)]
244+
[int]
245+
$WorkerVersion,
246+
194247
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
195248
[PsfArgumentCompleter('PSFramework-runspace-workflow-name')]
196249
[string[]]
@@ -202,6 +255,26 @@
202255
)
203256

204257
begin {
258+
$versionMap = @{
259+
2 = @('Timeout', 'RetryCount', 'RetryCondition')
260+
}
261+
$useVersion = 1
262+
263+
foreach ($version in $versionMap.Keys | Sort-Object) {
264+
foreach ($parameterName in $versionMap[$version]) {
265+
if ($PSBoundParameters.ContainsKey($parameterName)) {
266+
$useVersion = $version
267+
}
268+
}
269+
}
270+
271+
if ($WorkerVersion) {
272+
if ($WorkerVersion -lt $useVersion) {
273+
Stop-PSFFunction -String 'Add-PSFRunspaceWorker.Error.VersionTooLow' -StringValues $WorkerVersion, $useVersion -EnableException $true -Cmdlet $PSCmdlet -Category InvalidArgument
274+
}
275+
$useVersion = $WorkerVersion
276+
}
277+
205278
$functionsResolved = @{ }
206279

207280
if (-not $Functions) { return }
@@ -227,12 +300,19 @@
227300

228301
foreach ($resolvedWorkflow in $resolvedWorkflows) {
229302
$worker = $resolvedWorkflow.AddWorker($Name, $InQueue, $OutQueue, $ScriptBlock, $Count)
303+
$worker.WorkerVersion = $useVersion
230304

231305
if ($Begin) { $worker.Begin = $Begin }
232306
if ($End) { $worker.End = $End }
233307
if ($MaxItems) { $worker.MaxItems = $MaxItems }
234308
if ($CloseOutQueue) { $worker.CloseOutQueue = $true }
235309
if ($QueuesToClose) { $worker.QueuesToClose = $QueuesToClose }
310+
if ($Timeout) {
311+
$worker.Timeout = $Timeout
312+
$worker.TimeoutType = $TimeoutType
313+
}
314+
if ($RetryCount) { $worker.RetryCount = $RetryCount }
315+
if ($RetryCondition) { $worker.RetryCondition = $RetryCondition }
236316

237317
if ($SessionState) { $worker.SessionState = $SessionState }
238318
foreach ($module in $Modules) { $worker.Modules.Add($module) }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Reset-PSFRsAgentInactivity {
2+
<#
3+
.SYNOPSIS
4+
Signals the current Runspace Workflow Worker Agent(tm) is active.
5+
6+
.DESCRIPTION
7+
Signals the current Runspace Workflow Worker Agent is active.
8+
When called from within the code of a Runspace Workflow - specifically, within the code operated by a Generation 2+ Worker - it signals to the Worker-Agent that the current workload is being processed and is not hanging.
9+
10+
This is used by Generation 2+ Workers when they are configure for timeout type "Idle", where a timeout is performed based on how long the script code has not shown a sign of activity.
11+
An alternative way of showing activity is using the Write-PSFMessage command.
12+
13+
.EXAMPLE
14+
PS C:\> Reset-PSFRsAgentInactivity
15+
16+
Signals the current Runspace Workflow Worker Agent is active.
17+
#>
18+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
19+
[CmdletBinding()]
20+
param ()
21+
process {
22+
[PSFramework.Runspace.RunspaceHost]::SignalActive()
23+
}
24+
}

0 commit comments

Comments
 (0)