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

Preserve jobs order #180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

MVKozlov
Copy link
Contributor

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

@proxb
Copy link
Owner

proxb commented Mar 21, 2018

I think I will accept this one after #178 has been completed assuming that the OP gets back to my question in a reasonable amount of time.

@ChrisMagnuson
Copy link

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.

@MVKozlov
Copy link
Contributor Author

MVKozlov commented Nov 21, 2018

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

@ChrisMagnuson
Copy link

ChrisMagnuson commented Nov 21, 2018

@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.

@MVKozlov
Copy link
Contributor Author

it sounds still not clear to me. let's divide question...

  1. 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 }

  2. 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 }

@ChrisMagnuson
Copy link

ChrisMagnuson commented Nov 29, 2018

@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
}

@MVKozlov
Copy link
Contributor Author

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...

@MVKozlov
Copy link
Contributor Author

MVKozlov commented Dec 3, 2018

@ChrisMagnuson, fortunately for you, it was a calm morning :)

https://github.com/MVKozlov/PoshRSJob/tree/PerJobTimeout

@ChrisMagnuson
Copy link

@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?

@MVKozlov
Copy link
Contributor Author

MVKozlov commented Dec 4, 2018

I can make as many PR as need but @proxb seems have no time to visit here

@ChrisMagnuson
Copy link

@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.

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

Successfully merging this pull request may close these issues.

3 participants