-
Notifications
You must be signed in to change notification settings - Fork 86
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
Caveats of Start-RSJob -ModulesToImport #108
Comments
This looks like a side effect of allowing the commands to work with ForEach-Object. I'll have to think about how I want to handle this in either rolling back the change and taking away the ForEach-Object support or figuring out another way to do this. I'm not sure I want a -Force parameter with Start-RSJob as the users shouldn't have to worry about knowing when to force a new runspacepool to be created due to needing another module imported. At that point, they could just use a new batch name via the -Batch parameter and it would create a new runspacepool and import the module correctly. |
This affects more than just Quick example to show issue. Function Test {'This is a test'}
Function Test1 {1..10}
1|start-rsjob {Test} -FunctionsToLoad Test
1|start-rsjob {Test1} -FunctionsToLoad Test1 Second job will throw error about function Test1 not being found. At this point I consider this a breaking change brought on by #75 and plan on rolling it back to remove ForEach-Object support until I can have more time to look at it. |
I do not have any issues with this
|
It's working now because you are using the latest version (1.7.2.9) that fixed it. If you download 1.7.2.7, then there would be issues with your first example. I pretty much know where the issue is happening at in the code. I define the module/pssnapin/function point before I get to the runspacepools and if an existing one is used, then none of these things are loaded. I just need to load everything after I pick a runspacepool (either a new one or existing) and then attempt to add these into the mix. It definitely needs testing because I don't know yet if it will actually work. :) |
Yes, I need to read releasenotes.... but... You comment out both code branches - with and without I think that Start-RSJob should distinguish between pipeline and several independent launches and reuse runspace pool only when it detect pipeline input the best fix I know - generate batch name in
and do not test for |
I'm pretty sure I know how to solve the issue for Modules/Functions etc... in regards to making sure that they are updated properly; just need to get some time to update the code. Distinguishing the pipeline support for the jobs can be checked fairly simply by first looking at the named parameter for InputObject and then looking at the Process block. The big thing is making sure that we handle not only ForEach-Object, but also the ForEach keyword and even using other loops like While to ensure that all bases are covered. I started looking at using |
Get-PSCallstack has very poor performance. It's best not to call it in any looping code like a Process block. |
Yep. That and you would still have to parse the code to determine if the command was used in a loop. Although this wouldn't be used in a Process block and would have instead been done in the End block once to determine if it is in a loop or not. |
You want to support RunspacePool reusing automatically inside any loops ? I find it overkill feature because user can use
Are you sure user want to run both functions in the same Runspace ? I''m not I'm think than the one only loop that can guarantee that user want it run in the same runspace - is pipeline. All other - user desision. To use or not to use |
If a person wanted to use a foreach loop with the command, then they need to know that each command will create a new runspacepool (and lose any use of throttling) unless they use the Some good feedback and this does fit in with what I spent some of the day working on to ensure that only -Batch use will reuse the runspacepool and have it autogenerated in the Begin block. |
If you do desision about runspace reusing on code analysis then you probably can't catch code like this
and user will be disappointed on result because it will be breaking change with current (and past) module behaviour Both your and my examples have point of management with |
PoshRSJob 1.7.2.7 on PowerShell v5.
When you first use Start-RSJob, if you don't specify a -ModulesToImport, then on later runs of Start-RSJob the -ModulesToImport will not work and script blocks depending on those modules will fail.
This is because the runspaces have already been set up without the modules you wanted, and they haven't been torn down.
It's also worth mentioning there's no equivalent of a -Force for this. If you update the module, then it won't be reflected inside jobs in the run spaces (even when you start them later on).
The text was updated successfully, but these errors were encountered: