Use runspaces instead of PS job for plugin commands#201
Use runspaces instead of PS job for plugin commands#201Tadas wants to merge 3 commits intoposhbotio:masterfrom
Conversation
|
Once we're happy with the implementation I'll update docs to reflect the changes. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
@devblackops does this look OK? |
|
@Tadas This looks promising. Thanks for doing this! I just started testing and noticed a problem with retrieving the error stream. Try putting the command in a plugin: function Bad-Command {
[cmdletbinding()]
param()
Write-Error -Message "I'm error number one"
Write-Error -Message "I'm error number two"
}I haven't tracked it down but noticed the error isn't being returned from the runspace correctly and therefor, not sent back to Slack as a command response. |
|
This didn't catch my eye because my testing plugin was running with Your changes seem to have addressed this case which I'm happy about, but error handling still feels a bit off to me. Take this "improved" example: function Bad-CommandV2 {
[cmdletbinding()]
param()
$ErrorActionPreference = 'Continue'
Write-Output "ErrorActionPreference is $ErrorActionPreference"
Write-Error -Message "I'm error number one"
Write-Error -Message "I'm error number two"
Write-Error -Message "I'm error number three (ErrorAction Stop)" -ErrorAction Stop
Write-Error -Message "I'm error number four (ErrorAction Stop)" -ErrorAction Stop
}Using jobs implementation I only get a Using this PR I get a Meanwhile plain PowerShell outputs everything up to and including terminating error three. I guess it's bit of a UX question, when an error happens what should the user see?
|
|
I'm inclined to think I think that change is best made in another PR. To get this one in, can you rebase on master and resolve the conflicts? |
|
Agree on the separate PR 👍. Rebased |
Instead of using PowerShell background jobs which can be a bit slow since it involves creating a new process, use PowerShell .NET class and a separate runspace to run plugin commands.
Description
Introduced
[RunspaceJob]which replaces PowerShell's background job and is reponsible for starting and ending command execution in a separate runspace.Related Issue
Motivation and Context
PowerShell background jobs are slow to initialize, this way the bot responds quicker
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: