Powershell Throttle Multi thread jobs via job completion

后端 未结 6 1493
情歌与酒
情歌与酒 2020-12-07 03:23

All the tuts I have found use a pre defined sleep time to throttle jobs. I need the throttle to wait until a job is completed before starting a new one. Only 4 jobs can be r

6条回答
  •  失恋的感觉
    2020-12-07 04:05

    In order to avoid inventing a wheel I would recommend to use one of the existing tools.

    One of them is the script Invoke-Parallel.ps1. It is written in PowerShell, you can see how it is implemented directly. It is easy to get and it does not require any installation for using it.

    Another one is the module SplitPipeline. It may work faster because it is written in C#. It also covers some more use cases, for example slow or infinite input, use of initialization and cleanup scripts.

    In the latter case the code with 4 parallel pipelines will be

    $servers | Split-Pipeline -Count 4 {process{ <# DO STUFF on $_ #> }}
    

提交回复
热议问题