Skip to content

Commit

Permalink
renaming Dispatchers to Workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichWeinmann committed Nov 5, 2023
1 parent 1225600 commit 2cac301
Show file tree
Hide file tree
Showing 33 changed files with 443 additions and 412 deletions.
10 changes: 5 additions & 5 deletions PSFramework/PSFramework.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
'Get-PSFPipeline'
'Get-PSFResultCache'
'Get-PSFRunspace'
'Get-PSFRunspaceDispatcher'
'Get-PSFRunspaceWorkflow'
'Get-PSFRunspaceWorker'
'Get-PSFScriptblock'
'Get-PSFTaskEngineCache'
Expand All @@ -94,7 +94,7 @@
'New-PSFFilterConditionSet'
'New-PSFLicense'
'New-PSFMessageLevelModifier'
'New-PSFRunspaceDispatcher'
'New-PSFRunspaceWorkflow'
'New-PSFSessionContainer'
'New-PSFSupportPackage'
'New-PSFTempDirectory'
Expand Down Expand Up @@ -127,7 +127,7 @@
'Remove-PSFLicense'
'Remove-PSFLoggingProviderRunspace'
'Remove-PSFMessageLevelModifier'
'Remove-PSFRunspaceDispatcher'
'Remove-PSFRunspaceWorkflow'
'Remove-PSFTempItem'
'Reset-PSFConfig'
'Resolve-PSFDefaultParameterValue'
Expand All @@ -145,11 +145,11 @@
'Set-PSFTeppResult'
'Set-PSFTypeAlias'
'Start-PSFRunspace'
'Start-PSFRunspaceDispatcher'
'Start-PSFRunspaceWorkflow'
'Start-PSFRunspaceWorker'
'Stop-PSFFunction'
'Stop-PSFRunspace'
'Stop-PSFRunspaceDispatcher'
'Stop-PSFRunspaceWorkflow'
'Stop-PSFRunspaceWorker'
'Test-PSFFeature'
'Test-PSFFilter'
Expand Down
40 changes: 20 additions & 20 deletions PSFramework/functions/runspace/Add-PSFRunspaceWorker.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
function Add-PSFRunspaceWorker {
<#
.SYNOPSIS
Adds a new worker / workload to a runspace dispatcher.
Adds a new worker / workload to a runspace workflow.
.DESCRIPTION
Adds a new worker / workload to a runspace dispatcher.
Adds a new worker / workload to a runspace workflow.
The worker as a conceptually consists of three parts:
- Input Queue: A queue where data to process awaits
- N Runspaces to convert input to output
- Output Queue: A queue where the finished results are passed off to.
In the wider flow of a Runspace Workload Dispatcher, one Worker's Output Queue is alse another Worker's Input Queue.
In the wider flow of a Runspace Workflow, one Worker's Output Queue is alse another Worker's Input Queue.
Thus we create a chain of workers from original input to finished output, each step individually with as many runspaces as needed.
.PARAMETER Name
Name of the worker.
The name matters little, other than that it must be unique from other workers on the same Dispatcher.
The name matters little, other than that it must be unique from other workers on the same workflow.
.PARAMETER InQueue
Name of the queue from which to receive input.
The name is arbitrary - if the queue does not yet exist on the dispatcher, it will be auto-created.
The name is arbitrary - if the queue does not yet exist on the workflow, it will be auto-created.
.PARAMETER OutQueue
Name of the queueue to which we write output.
The name is arbitrary - if the queue does not yet exist on the dispatcher, it will be auto-created.
The name is arbitrary - if the queue does not yet exist on the workflow, it will be auto-created.
.PARAMETER ScriptBlock
The scriptblock performing the actual workload.
Expand Down Expand Up @@ -89,30 +89,30 @@
A fully prepared session state object to use when creating the worker runspaces.
Be aware that if your session state does not contain basic language tools, the background runspace will likely fail.
.PARAMETER DispatcherName
Name of the Runspace Dispatcher this worker belongs to.
The dispatcher contains all the workers, queues and management tools for the Runspace Workload.
.PARAMETER WorkflowName
Name of the Runspace Workflow this worker belongs to.
The workflow contains all the workers, queues and management tools for the Runspace Workload.
.PARAMETER InputObject
Dispatcher object of the Runspace Dispatcher this worker belongs to.
The dispatcher contains all the workers, queues and management tools for the Runspace Workload.
Workflow object this worker belongs to.
The workflow contains all the workers, queues and management tools for the Runspace Workload.
.EXAMPLE
PS C:\> $dispatcher | Add-PSFRunspaceWorker -Name DoubleIt -InQueue Q1 -OutQueue Q2 -Count 5 -ScriptBlock { $args[0] * 2 }
PS C:\> $workflow | Add-PSFRunspaceWorker -Name DoubleIt -InQueue Q1 -OutQueue Q2 -Count 5 -ScriptBlock { $args[0] * 2 }
Adds a worker to the dispatcher that will take items from Q1, double them, then write them to Q2.
Adds a worker to the workflow that will take items from Q1, double them, then write them to Q2.
Will create 5 runspaces to do the job.
.EXAMPLE
PS C:\> $dispatcher | Add-PSFRunspaceWorker -Name Mailboxes -InQueue Organizations -OutQueue Mailboxes -Count 1 -Variables $connectionData -Begin $logonScript -ScriptBlock $getMailbox -End $logoutScript
PS C:\> $workflow | Add-PSFRunspaceWorker -Name Mailboxes -InQueue Organizations -OutQueue Mailboxes -Count 1 -Variables $connectionData -Begin $logonScript -ScriptBlock $getMailbox -End $logoutScript
Adds a worker that will for each organization retrieve the mailboxes.
Will create 1 runspace to avoid hitting EXO throttling.
More detailed examples and explanations can be found on psframework.org.
TODO: Update link to section once available.
https://psframework.org/documentation/documents/psframework/runspace-workflows.html
.LINK
TODO: Add link to section
https://psframework.org/documentation/documents/psframework/runspace-workflows.html
#>
[CmdletBinding()]
param (
Expand Down Expand Up @@ -164,7 +164,7 @@

[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string[]]
$DispatcherName,
$WorkflowName,

[Parameter(ValueFromPipeline = $true)]
[PSFramework.Runspace.RSDispatcher[]]
Expand Down Expand Up @@ -193,10 +193,10 @@
}
}
process {
$resolvedDispatchers = Resolve-PsfRunspaceDispatcher -Name $DispatcherName -InputObject $InputObject -Cmdlet $PSCmdlet -Terminate
$resolvedWorkflows = Resolve-PsfRunspaceWorkflow -Name $WorkflowName -InputObject $InputObject -Cmdlet $PSCmdlet -Terminate

foreach ($resolvedDispatcher in $resolvedDispatchers) {
$worker = $resolvedDispatcher.AddWorker($Name, $InQueue, $OutQueue, $ScriptBlock, $Count)
foreach ($resolvedWorkflow in $resolvedWorkflows) {
$worker = $resolvedWorkflow.AddWorker($Name, $InQueue, $OutQueue, $ScriptBlock, $Count)

if ($Begin) { $worker.Begin = $Begin }
if ($End) { $worker.End = $End }
Expand Down
16 changes: 8 additions & 8 deletions PSFramework/functions/runspace/Get-PSFRunspaceDispatcher.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
function Get-PSFRunspaceDispatcher {
function Get-PSFRunspaceWorkflow {
<#
.SYNOPSIS
Returns a list of registered runspace dispatchers.
Returns a list of registered runspace workflows.
.DESCRIPTION
Returns a list of registered runspace dispatchers.
A Runspace dispatcher is the main component managing a PSFramework Runspace Workflow
Returns a list of registered runspace workflows.
A Runspace workflow object is the main component managing a PSFramework Runspace Workflow
.PARAMETER Name
By which name to filter.
Defaults to *
.EXAMPLE
PS C:\> Get-PSFRunspaceDispatcher
PS C:\> Get-PSFRunspaceWorkflow
Returns all registered runspace dispatchers.
Returns all registered runspace workflows.
.LINK
TODO: Add link to section
https://psframework.org/documentation/documents/psframework/runspace-workflows.html
#>
[CmdletBinding()]
param (
[string]
$Name = '*'
)
process {
($script:runspaceDispatchers.Values | Where-Object Name -Like $Name)
($script:runspaceWorkflows.Values | Where-Object Name -Like $Name)
}
}
26 changes: 13 additions & 13 deletions PSFramework/functions/runspace/Get-PSFRunspaceWorker.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
function Get-PSFRunspaceWorker {
<#
.SYNOPSIS
Retrieve workers associated with a Runspace Dispatcher.
Retrieve workers associated with a Runspace Workflow.
.DESCRIPTION
Retrieve workers associated with a Runspace Dispatcher.
Retrieve workers associated with a Runspace Workflow.
.PARAMETER Name
Name of the worker to filter by.
Defaults to *
.PARAMETER DispatcherName
Name of the Runspace Dispatcher from which to retrieve workers.
The dispatcher contains all the workers, queues and management tools for the Runspace Workload.
.PARAMETER WorkflowName
Name of the Runspace Workflow from which to retrieve workers.
The workflow contains all the workers, queues and management tools for the Runspace Workflow.
.PARAMETER InputObject
Dispatcher object of the Runspace Dispatcher from which to retrieve workers.
The dispatcher contains all the workers, queues and management tools for the Runspace Workload.
Workflow object from which to retrieve workers.
The workflow contains all the workers, queues and management tools for the Runspace Workflow.
.EXAMPLE
PS C:\> Get-PSFRunspaceDispatcher | Get-PSFRunspaceWorker
PS C:\> Get-PSFRunspaceWorkflow | Get-PSFRunspaceWorker
Get all workers of all runspace dispatchers.
Get all workers of all runspace workflows.
.LINK
TODO: Add link to section
https://psframework.org/documentation/documents/psframework/runspace-workflows.html
#>
[CmdletBinding()]
param (
Expand All @@ -33,15 +33,15 @@

[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string[]]
$DispatcherName,
$WorkflowName,

[Parameter(ValueFromPipeline = $true)]
[PSFramework.Runspace.RSDispatcher[]]
$InputObject
)
process {
$resolvedDispatchers = Resolve-PsfRunspaceDispatcher -Name $DispatcherName -InputObject $InputObject -Cmdlet $PSCmdlet
$resolvedWorkflows = Resolve-PsfRunspaceWorkflow -Name $WorkflowName -InputObject $InputObject -Cmdlet $PSCmdlet

$resolvedDispatchers.Workers.Values | Where-Object Name -Like $Name
$resolvedWorkflows.Workers.Values | Where-Object Name -Like $Name
}
}
57 changes: 0 additions & 57 deletions PSFramework/functions/runspace/New-PSFRunspaceDispatcher.ps1

This file was deleted.

57 changes: 57 additions & 0 deletions PSFramework/functions/runspace/New-PSFRunspaceWorkflow.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function New-PSFRunspaceWorkflow {
<#
.SYNOPSIS
Creates a new runspace workflow.
.DESCRIPTION
Creates a new runspace workflow.
The workflow object is the core element of the runspace workflow system.
It contains the workers, runspaces and queues that execute the workflow.
All workflows are stored centrally and cen be retrieved using Get-PSFRunspaceWorkflow.
To ensure proper cleanup, remember to use Remove-PSFRunspaceWorkflow when completed.
.PARAMETER Name
The name of the workflow to create.
Must be unique in the current runspace.
.PARAMETER Force
Allows overwriting an existing workflow of the same name.
Note: Doing so will terminate all processing on the previous workflow.
.EXAMPLE
PS C:\> New-PSFRunspaceWorkflow -Name 'MyModule.MyWorkflow
Creates a new Runspace Workflow with the name 'MyModule.MyWorkflow'
.LINK
https://psframework.org/documentation/documents/psframework/runspace-workflows.html
.LINK
Get-PSFRunspaceWorkflow
.LINK
Remove-PSFRunspaceWorkflow
#>
[OutputType([PSFramework.Runspace.RSDispatcher])]
[CmdletBinding()]
param (
[string]
$Name,

[switch]
$Force
)
process {
if ($script:runspaceWorkflows[$Name]) {
if (-not $Force) {
Stop-PSFFunction -String 'New-PSFRunspaceWorkflow.Error.ExistsAlready' -StringValues $Name -EnableException $true -Cmdlet $PSCmdlet
}

$script:runspaceWorkflows[$Name].Stop()
}

$script:runspaceWorkflows[$Name] = [PSFramework.Runspace.RSDispatcher]::new($Name)
$script:runspaceWorkflows[$Name]
}
}
Loading

0 comments on commit 2cac301

Please sign in to comment.