PoshRSJob
PoshRSJob copied to clipboard
Preserve jobs order
Fixes #179.
Changes proposed in this pull request:
Job order for Get-RSJob
preserved from input to output
How to test this code:
PS C:\> 1..10 | Start-RSJob {
>> if (1 -BAND $_) {
>> "First ($_)"
>> } Else {
>> Start-sleep -seconds 2
>> "Last ($_)"
>> }
>> } | Wait-RSJob | Receive-RSJob
First (1)
First (3)
First (5)
First (7)
First (9)
Last (2)
Last (4)
Last (6)
Last (8)
Last (10)
Has been tested on (remove any that don't apply):
- Powershell 2 and above
- Windows 7 and above
I think I will accept this one after https://github.com/proxb/PoshRSJob/pull/178 has been completed assuming that the OP gets back to my question in a reasonable amount of time.
I know this is a little old but I would like to be able to use the streaming aspect of Wait-RSJob so that as jobs complete I can immediately start another long running single threaded processes so that they are going through that downstream process as soon as they are individually done, not once all of them are done.
so, you want single threading ? may be just not use RSJob ? :) or may be join multiple jobs inside one ?
or, if you want to start the same jobs with different data, then look to -Throttle 1
because Wait-RSJob
return Job object, not data
@MVKozlov I am sorry I must not have been clear, I want to process a set of asynchronous jobs as soon as each one is complete.
To do this I would need the streaming functionality that passes whichever jobs have reached completion down the pipeline as soon as the job is complete.
it sounds still not clear to me. let's divide question...
-
Do you want to run the different jobs each time or the same with different data ?
$data1 | { scriptblock-1 }
$data2 | { scriptblock-2 }
or$data1 | { scriptblock-1 }
$data2 | { scriptblock-1 }
-
Do you want your output from scriptblocks go to into next scriptblock or it is fully independent and just need to be run sequidentally ?
$data1 | { scriptblock-1 } | { scriptblock-2 }
or$data1 | { scriptblock-1 }
,$data2 | { scriptblock-2 }
@MVKozlov I have created some sample code below that I think will help explain.
I believe this is closest to the $data1 | { scriptblock-1 } | { scriptblock-2 }
scenario you listed above but it would be more like $data1,$data2 | { scriptblock-1 } | { scriptblock-2 }
:
$ArrayOfObjects = [PSCustomObject]@{
URL1 = "https://domain.com/file83423"
URL2 = "https://domain.com/file88234"
},
[PSCustomObject]@{
URL1 = "https://domain.com/file12342"
URL2 = "https://domain.com/file84342"
}
$ArrayOfObjects |
Start-RSJob -ScriptBlock { ScriptBlockToDownloadFilesFromURLs } |
Wait-RSJob |
Receive-RSJob |
ForEach-Object -Process {
#This should be executed the moment any job has downloaded both of its two files
ScriptBlockToDoSomethingWithTheTwoFilesPerIndividualJob
#This should keep being executed as each individual set of two downloaded files is passed to it by jobs that have completed
#This happens in whatever order the jobs complete, not in the order of the $ArrayOfObjects
}
ok, now I see. but seems there is no method to accomplish this task, sorry. I have a plans to redesign commands to property support pipeline but have no time just now. and @proxb still not approve previous PRs...
@ChrisMagnuson, fortunately for you, it was a calm morning :)
https://github.com/MVKozlov/PoshRSJob/tree/PerJobTimeout
@MVKozlov Nice!
I cloned this and ran the example from PoshRSJob README.md and now the example works again:
PS > 1..10|Start-RSJob {
>> if (1 -BAND $_){
>> "First ($_)"
>> }Else{
>> Start-sleep -seconds 2
>> "Last ($_)"
>> }
>> }|Wait-RSJob|Receive-RSJob|ForEach{"I am $($_)"}
I am First (1)
I am First (3)
I am First (5)
I am First (7)
I am First (9)
I am Last (2)
I am Last (4)
I am Last (6)
I am Last (8)
I am Last (10)
Will there be another separate PR for this?
I can make as many PR as need but @proxb seems have no time to visit here
@MVKozlov I see what you mean, don't see much activity from @proxb since February.
I will focus on trying to use that branch of your fork in our code for now.