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

Invoke-parallel Ignores wait commands #40

Closed
heygautam opened this issue Nov 23, 2016 · 5 comments
Closed

Invoke-parallel Ignores wait commands #40

heygautam opened this issue Nov 23, 2016 · 5 comments

Comments

@heygautam
Copy link

Invoke-parallel seems to ignore wait commands which are built-into the PS modules I am using in my script.

Here’s what I am doing

  1. The script works against an input CSV which has multi rows and columns.

  2. The script’s goal is to restore a VM from Azure Recovery Services– this restore can take 30 minutes and more per VM. I want to run the restore operations in parallel.

  3. The Restore operations involves 2 main actions
    a. Restore VM from Azure Recovery Vault. This can take 30 minutes and more.
    b. The Azure Recovery Vault PS commands have the logic to wait for the restore to complete before proceeding to the next line. When I run the script without invoke-parallel, the sequence of steps is as expected - first finish 3b and then proceed to 3c.
    c. Create a new VM based on the output from (a) above.

  4. Currently, the script can successfully do these operations for multiple VMs, but only serially.

Questions: With invoke-parallel, the Restore VM Operations gets kicked off in parallel but for whatever reason it doesn’t wait for the restore to finish. It immediately moves ahead to Create new VM (3c) which obviously fails since the VM hasn’t yet be restored. The logic to wait is ignored when using invoke-parallel. (3c)

Anyone know how to fix this?

@RamblingCookieMonster
Copy link
Owner

That sounds odd! So, to clarify, these commands typically don't return right away, they wait until the restore is complete, and then pass through some object?

What command is it, or, if it's a function/script, would you mind sanitizing and posting? On that note, an example that could reproduce the issue would be handy as well

Cheers!

@heygautam
Copy link
Author

Hi, Thanks for the reply.

You are correct in your understanding!

The entire script is attached. It's based off of a script I found on TechNet. Only the csv import is customized.
RestoreVM.txt

I call both 3b and 3c in a scriptblock which I process using invoke-parallel like so....
Invoke-Parallel -ImportVariables -ScriptBlock

The exact commands are:

  1. This kicks off the restore....
    Restore-AzureRmRecoveryServicesBackupItem -RecoveryPoint $_ -StorageAccountName $ExistingStorAcct.StorageAccountName -StorageAccountResourceGroupName $ExistingStorAcct.ResourceGroupName

  2. This command adds the wait. Post this the script goes ahead and creates a new VM based on the restore.
    $joblist = Get-AzureRmRecoveryServicesBackupJob -JobId $restorejob.JobId
    Wait-AzureRmRecoveryServicesBackupJob -Job $joblist -Timeout 43200

@heygautam
Copy link
Author

Hi, I pinged in to ask if you got a chance to look at this. I can't make heads-tails of the issue.

@RamblingCookieMonster
Copy link
Owner

Hi! Apologies, flipped through it but didn't see anything initially - will be tied up with a conference and holidays, but, will try to revisit next year - ping me late January or early February

In the interim, you might consider pinging folks in the Rest Azured Slack team

Cheers!

@heygautam
Copy link
Author

heygautam commented Nov 30, 2016 via email

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

No branches or pull requests

2 participants