-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customizing and Managing Runspace Names #1384
Conversation
I like the idea of This way, all Pode Runspaces get a default standardised name and if people need/want to set a different name they have that capability available to them as well. I'm happy with the setting of the primary I would also be very careful with Timers. The main Timer scheduler runspace will be named, but the runspace rename will change the scheduler runspace name; so the rapid renaming might get confusing, and it would never rename back to the original "scheduler" name so would look like one timer never ended. I'm thinking the internal naming structure some be something like
The $rsName = "Pode_$($Type)_$($Name)_$($Id)" Where if (!$NoProfile) {
$null = $ps.AddScript("Open-PodeRunspace -Type '$($Type)'")
} to the following, where we pass the Name and NoProfile switch - removing the NoProfile $null = $ps.AddScript("Open-PodeRunspace -Type '$($Type)' -Name '$($rsName)' -NoProfile:`$$($NoProfile.IsPresent)") Add then the try {
# set runspace name
Set-PodeCurrentRunspaceName -Name $Name
if (!$NoProfile) {
# Importing internal Pode modules necessary for the runspace operations.
Import-PodeModulesInternal
# Adding PowerShell drives required by the runspace.
Add-PodePSDrivesInternal
}
# Setting the state of the runspace pool to 'Ready', indicating it is ready to process requests.
$PodeContext.RunspacePools[$Type].State = 'Ready'
}
catch {
# ... unchanged ...
} This would change, for example, the web listener runspace creation to: 1..$PodeContext.Threads.General | ForEach-Object {
Add-PodeRunspace -Type Web -Name 'Listener' -Id $_ -ScriptBlock $listenScript -Parameters @{ 'Listener' = $listener; 'ThreadId' = $_ }
} Or for Logging: Add-PodeRunspace -Type Main -Name 'Logging' -ScriptBlock $script Or when a Schedule triggers in $runspace = Add-PodeRunspace -Type Schedules -Name $Schedule.Name -ScriptBlock $scriptblock -Parameters $parameters -PassThru |
I like that. |
Done but there is a bug in your last commit bug #1395 |
Recovered from Naming Runspaces #1364
Description of the Change
Assign a name to each runspace
Related Issue
#1363
Customizing and Managing Runspace Names
Distinguishing Runspace Names in Pode
In Pode, internal runspaces are automatically assigned distinct names. This naming convention helps in identifying and managing these runspaces efficiently during debugging and monitoring. However, this is not the case for runspaces created by user tasks and schedules (excluding AsyncTask). These user-created runspaces typically have names in the
Runspace<number>
format, which can make it challenging to distinguish between different runspaces.Customizing Runspace Names
By default, Pode’s Tasks, Schedules, and Timers use their own names to label their associated runspaces, making it easier to identify them during debugging and monitoring.
However, if you wish to use a different name for the runspace, you can invoke
Add-PodeTask
,Add-PodeSchedule
, orAdd-PodeTimer
with the-DisableRunspaceNaming
parameter.Then, within the script block, you can use the Set-PodeCurrentRunspaceName cmdlet to assign any custom name you prefer.
Another useful cmdlet is
Get-PodeCurrentRunspaceName
, which retrieves the current runspace's name. This can be helpful if you need to log or display the runspace name dynamically.Example
Here is an updated example demonstrating how to set a custom runspace name in a Pode task:
In this example, the
Set-PodeCurrentRunspaceName
cmdlet is used to assign the custom name 'My Fancy Runspace' to the runspace executing the task, enhancing identification during debugging or in logs.Retrieving Runspace Names
Another useful cmdlet is
Get-PodeCurrentRunspaceName
, which retrieves the current runspace's name. This cmdlet can be particularly helpful if you need to log or display the runspace name dynamically during execution. It allows you to track and manage runspaces effectively, especially in complex scenarios where multiple runspaces are running concurrently.