Actually I think a better solution here might be to create temporary files during the parallelized code block, then I can create the octopus artifacts from those files once execution returns to the main thread….
From: Prudente, Tony
Sent: Wednesday, July 27, 2016 10:31 AM
To: 'Dalmiro Grañas’
Subject: RE: Parallelization in Powershell Scripts [Questions #8589]
Re-attaching scripts with different extension
From: Prudente, Tony
Sent: Wednesday, July 27, 2016 10:30 AM
To: 'Dalmiro Grañas’
Subject: RE: Parallelization in Powershell Scripts [Questions #8589]
Thanks for getting back!
Indeed, my current setup already has one tentacle per database server and my script handles figuring out which databases the tentacle should deploy to (which are the ones on the server the tentacle runs on). So this provides the first level of parallelization simply by way of having more than one db server, but unfortunately that isn’t enough. A single server could have 80 customer databases on it, and at 2-3 minutes per database, I need another level of paralellization still.
I might be close to a solution. I’ve used the Invoke-Parallel cmdlet from the Technet Galleryhttps://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430, which takes the list of databases as an input, and essentially operates like a Parallel.Foreach in C#.
The only snag I’m running into is that, because Invoke-Parallel uses runspaces as a method of parallelization, I need to explicitly import the Octopus cmdlets within the parallel script block. For whatever reason, the Redgate cmdlets are already present in the runspace context, but the Octopus ones are not. In my deploy script (attached), you’ll see where I invoke New-OctopusArtifact, and the script blows up at this point saying it is an unrecognized command. The Invoke-Parallel documentation says you need to import the snapin or module where these things are defined since they’re not automatically imported into the background runspace.
Where would I find the Octopus powershell cmdlets - in other words how to import them in the $scriptBlock?
I’ve attached the following files:
- OctopusDbDeploy.ps1 (my custom Octopus deploy script)
- Invoke-Parallel.ps1 (the script from TechNet, for reference)
- Server
Thanks for your help - I should mention I’m a C# / SQL / Web developer so Powershell is not my top skill. Also wanted to mention that we’re a paid (Enterprise) customer.
Regards,
Tony