RamblingCookieMonster / Invoke-Parallel

Speed up PowerShell with simplified multithreading
MIT License
384 stars 88 forks source link

Invoke-parallel Ignores wait commands #40

Closed heygautam closed 3 years ago

heygautam commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Will do, cheers

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Warren Framemailto:notifications@github.com Sent: Wednesday, November 30, 2016 07:27 To: RamblingCookieMonster/Invoke-Parallelmailto:Invoke-Parallel@noreply.github.com Cc: heygautammailto:heygautam@hotmail.com; Authormailto:author@noreply.github.com Subject: Re: [RamblingCookieMonster/Invoke-Parallel] Invoke-parallel Ignores wait commands (#40)

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 teamhttp://azured.io/join

Cheers!

- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/RamblingCookieMonster/Invoke-Parallel/issues/40#issuecomment-263760003, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AS5Zj1W8dEYKcXV5AihEAHw16-JGWJ_Oks5rDNgYgaJpZM4K6lT1.