Skip to content
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

RSJob on PSv2 #136

Closed
MVKozlov opened this issue Mar 17, 2017 · 7 comments
Closed

RSJob on PSv2 #136

MVKozlov opened this issue Mar 17, 2017 · 7 comments
Assignees
Labels

Comments

@MVKozlov
Copy link
Contributor

MVKozlov commented Mar 17, 2017

Jobs can't set it's state on powershell v2

PS C:\> import-module poshrsjob
PS C:\> (get-module poshrsjob).version
Major  Minor  Build  Revision
-----  -----  -----  --------
1      7      3      5
PS C:\> 1..3|start-rsjob { $_ }

Id       Name                 State           HasMoreData  HasErrors    Command
--       ----                 -----           -----------  ---------    -------
1        Job1                                              {}            $_
2        Job2                                              {}            $_
3        Job3                                              {}            $_

What is the expected behavior?

PS C:\> import-module poshrsjob
PS C:\> (get-module poshrsjob).version
Major  Minor  Build  Revision
-----  -----  -----  --------
1      7      3      4
PS C:\> 1..3|start-rsjob { $_ }
Id       Name                 State           HasMoreData  HasErrors    Command
--       ----                 -----           -----------  ---------    -------
1        Job1                 Running         False        {}            $_
2        Job2                 Running         False        {}            $_
3        Job3                 Running         False        {}            $_

actually Jobs a running but it's State not set, so Wait-RSJob does not exit

@MVKozlov MVKozlov changed the title v1.7.3.5 broke PSv2 v1.7.3.5 broke PSv2 Wait-RSJob Mar 17, 2017
@MVKozlov MVKozlov changed the title v1.7.3.5 broke PSv2 Wait-RSJob v1.7.3.5 broke Wait-RSJob on PSv2 Mar 17, 2017
@MVKozlov
Copy link
Contributor Author

MVKozlov commented Mar 17, 2017

hmm... Everything is much worse than I thought
even in v1.7.2.4

import-module poshrsjob
1..3|start-rsjob { start-sleep -sec 15; $_ }

take 45 sec to exit to prompt
while measure-command { 1..3|start-rsjob { start-sleep -sec 15; $_ } } or $jobs = 1..3 | start-rsjob { $_ }
takes milliseconds to run, get-rsjob or $jobs right after that take 15 sec to display job list

sorry, have no time to check earlier versions today :(

@MVKozlov MVKozlov changed the title v1.7.3.5 broke Wait-RSJob on PSv2 RSJob on PSv2 Mar 17, 2017
@proxb
Copy link
Owner

proxb commented Mar 17, 2017

I really need to figure out and fix the issue with AppVeyor that broke my V2 tests. I think I saw a PR over at @RamblingCookieMonster Invoke-Parallel (RamblingCookieMonster/Invoke-Parallel#41) that I might steal from to get it working again.

In the meantime, it looks like some background stuff that uses reflection for the Types may not be V2 compatible (https://github.com/proxb/PoshRSJob/blob/master/PoshRSJob/TypeData/PoshRSJob.Types.ps1xml). I'll have to test more in V2 and figure out the best way to handle that. I don't really want to lose this functionality due to V2 as it provides better state tracking of RSJobs.

@MVKozlov
Copy link
Contributor Author

Just did another test v2 with 1..3|start-rsjob { start-sleep -sec 15; $_ }
seems that delay exists when job object outputs it's values to host
If I do

$j = 1..3 | Start-RSJob { start-sleep -sec 15; $_ }
start-sleep -sec 14
$j

delay while outputting jobs from $j does not appear, so it's really .Types related.
but disappearing the State's for v2 is the real problem because of suspended Wait-RSJob

@proxb
Copy link
Owner

proxb commented Mar 17, 2017

I found the issue with the disappearing states which was due to one of the techniques that I use for reflection was missing some of the other parameters that exists in V3+. Luckily it was a simple fix by adding $Null as the second parameter and it supports V2+.

Before
PowerShell $CRP = $_CRP.GetValue($Worker)

After
PowerShell $CRP = $_CRP.GetValue($Worker,$Null)

I couldn't reproduce the delay either after making that change so this may solve both items. I'll add this to the list of things when I upload the next version tonight or tomorrow.

@MVKozlov
Copy link
Contributor Author

Another v2 error (I continue to report here)
ConvertScriptBlockV2 does not support $v -is [type] syntax

PS D:\> $a = 1; $a -is [array]
False
PS D:\> $a | Start-RSJob { $_ -is [array] }
Create : Exception calling "Create" with "1" argument(s): "You must provide a value expression on the right-hand side o
f the '-is' operator."
At PoshRSJob\Private\ConvertScriptBlockV2.ps1:88 char:26

debug show that scriptblock converted to Param($_)$_ -is array
workaround: $_ -is "array"

@MVKozlov
Copy link
Contributor Author

MVKozlov commented Mar 21, 2017

start-sleep issue not fixed, but I fix all other in my fork latest commit
#42 too

@proxb proxb self-assigned this Apr 3, 2017
@proxb proxb added the bug label Apr 3, 2017
@proxb proxb closed this as completed Apr 9, 2017
@MVKozlov
Copy link
Contributor Author

MVKozlov commented May 5, 2017

About Start-Sleep inside scriptblock on PSv2
Seems I found a fix

--- a/PoshRSJob/TypeData/PoshRSJob.Types.ps1xml
+++ b/PoshRSJob/TypeData/PoshRSJob.Types.ps1xml
@@ -83,7 +83,7 @@
             $this.innerjob.HadErrors
          }
          Else {
-            ($this.innerjob.Streams.Error -ne $null)
+            ($this.innerjob.Streams.Error.Count -ne 0)
          }
         </GetScriptBlock>
       </ScriptProperty>

let it be here until widely tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants