Invoke-Parallel icon indicating copy to clipboard operation
Invoke-Parallel copied to clipboard

Convert .ps1 to .psm1

Open vors opened this issue 10 years ago • 13 comments

Modules is the preferred way to distribute reusable components.

vors avatar Mar 04 '15 00:03 vors

Agreed - any issue with a mild file re-org?

  • \Invoke-Parallel\
    • \Invoke-Parallel.psm1
  • \Tests\
    • \Invoke-Parallel.Tests.ps1
    • \AppVeyor-Pester.ps1 (abstracted calls to pester to test PS2 as well, example here)
  • \appveyor.yml
  • \README.md
  • \LICENSE.md

Let me know if you see any issues with this!

RamblingCookieMonster avatar Mar 04 '15 01:03 RamblingCookieMonster

Looks good

vors avatar Mar 04 '15 01:03 vors

Also, after that's done it would make sense to add .psd1 file and publish it to PsGet gallery (and maybe PowerShellGet gallery). .psd1 file would help with versioning (it's the only option to provide a version)

vors avatar Mar 04 '15 01:03 vors

Absolutely!

Running into a strange issue in the Restructure branch. Having moved to a psm1, the ImportVariable Pester tests are now failing to find the user's variables.

Global, Script, Local, 0, 1, and 2 all do not contain variables with name 'a' and 'long'. Running the same code in the pester test works in my local session:

Successful run outside of Pester:

image

Failed run in Pester (Added temporary verbose output to illustrate what Get-Variable can see)

The Pester test fails when invoked directly on my system as well (i.e. not an issue exclusive to appveyor.pester.ps1).

Will keep tinkering.

RamblingCookieMonster avatar Mar 04 '15 14:03 RamblingCookieMonster

Yeah, I can reproduce this, https://gist.github.com/RamblingCookieMonster/05552112507db8a04246

Learned something about scope and encapsulation!

I'm assuming this might be a mutually exclusive choice between moving to a module, and allowing ImportVariables to work in all scenarios?

Ugly alternative might be to have Invoke-Parallel.psd1, Invoke-Parallel.psm1, which load up Invoke-Parallel.ps1, allowing users to dot source Invoke-Parallel.ps1 outside the module if they want to use that functionality. Would need to vary the scope for the Get-Variable call.

RamblingCookieMonster avatar Mar 04 '15 16:03 RamblingCookieMonster

That's interesting. I don't think it's mutually exclusive. Need to dig into it.

vors avatar Mar 04 '15 18:03 vors

Sheepish... Created a branch for the changes, committed changes to master. Heading out for caffeine. If it would make sense let me know and I can revert master and roll this in with a merge.

Sorry about that!

RamblingCookieMonster avatar Mar 04 '15 19:03 RamblingCookieMonster

No worries, I think it's fine to make a force push to master in this case.

vors avatar Mar 04 '15 19:03 vors

How far did you get with this, is there a working module that can be used for executing a script block rather than dot sourcing?

davidwallis avatar Sep 21 '16 09:09 davidwallis

Nope, unfortunately, I've sort of let this project languish given the excellent PoshRSJob module by Boe. There are a few other issues that I might tackle, but this is pretty low on the priority list given what (I assume) it will take... unless we can just use ScriptsToProcess in the manifest?

If you have any ideas on how to implement this, or code, totally open to pull requests : D

Cheers!

RamblingCookieMonster avatar Sep 22 '16 16:09 RamblingCookieMonster

Import-Modue Invoke-Parallel $filelist | Invoke-Parallel -ImportVariables -Throttle 10 -ScriptBlock { ...

Get-RunspaceData : You cannot call a method on a null-valued expression. At C:\Users\ImN1\Documents\WindowsPowerShell\Modules\Invoke-Parallel\Invoke-Parallel.psm1:542 char:13

  •         Get-RunspaceData -wait
    
  •         ~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [Write-Error], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull,Get-RunspaceData

but No error by ". \PATH\Invoke-Parallel.ps1"

ImN1 avatar Jul 10 '17 04:07 ImN1

fyi. This module needs to be dot sourced I believe. I have never had an error while using . Script while you probably are running into some scope issues with trying to import.

@RamblingCookieMonster I will say I've used both your project and the PoshRSJob. I find your script to be vastly simpler to implement most times. You did a great job on this!

sheldonhull avatar Jul 10 '17 22:07 sheldonhull

What is preventing this from moving forward?

Silex avatar Jan 13 '21 07:01 Silex