Coder Social home page Coder Social logo

Convert .ps1 to .psm1 about invoke-parallel HOT 13 OPEN

vors avatar vors commented on June 17, 2024
Convert .ps1 to .psm1

from invoke-parallel.

Comments (13)

vors avatar vors commented on June 17, 2024 2

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)

from invoke-parallel.

sheldonhull avatar sheldonhull commented on June 17, 2024 1

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!

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on June 17, 2024

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!

from invoke-parallel.

vors avatar vors commented on June 17, 2024

Looks good

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on June 17, 2024

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.

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on June 17, 2024

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.

from invoke-parallel.

vors avatar vors commented on June 17, 2024

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

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on June 17, 2024

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!

from invoke-parallel.

vors avatar vors commented on June 17, 2024

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

from invoke-parallel.

davidwallis3101 avatar davidwallis3101 commented on June 17, 2024

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?

from invoke-parallel.

RamblingCookieMonster avatar RamblingCookieMonster commented on June 17, 2024

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!

from invoke-parallel.

ImN1 avatar ImN1 commented on June 17, 2024

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"

from invoke-parallel.

Silex avatar Silex commented on June 17, 2024

What is preventing this from moving forward?

from invoke-parallel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.