Job tracker - throtting jobs

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Job tracker - throtting jobs

Post by robert.ganshorn »

I am using the job tracker to launch multiple jobs, but only a few can run concurrently or I start getting call depth overflow errors.

Is it possible to queue jobs or launch jobs, but throttle them based upon a job count value? All while keeping the gui responsive of course. I can easily do it within the main form, but of course then the form freezes in the 'while' loop.

Rob
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job tracker - throtting jobs

Post by jvierra »

Yes but you will have to modify the job tracker extensively or, better yet, use a workflow.
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Re: Job tracker - throtting jobs

Post by robert.ganshorn »

On a side note, I resolved this by creating temporary .job files for each job as they are launched. To keep started jobs from all running at the exact same time, there is a small random delay period in the startup of each job to stagger their start. The .job files are used to keep track of the jobs running and are removed as they complete. Each job count the .job files and loop when there are 4 or more. Maybe it's not the most elegant solution, but it works and isn't too convoluted. .job files are named after the job in question (ie: job1.job, job2.job etc).

Rob
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job tracker - throtting jobs

Post by jvierra »

You can just add a queuing mechanism to JobTracker and it will do the same thing and much more efficiently.
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Re: Job tracker - throtting jobs

Post by robert.ganshorn »

Can you show an example?

Rob
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job tracker - throtting jobs

Post by jvierra »

I don't have an example.
Look into System.Collections.Generic.Queue
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Job tracker - throtting jobs

Post by apowershelluser »

I was hoping the same
I have a job that runs, 90% completes very quickly and displays and we have to wait another 10 seconds for the last job to finish
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Job tracker - throtting jobs

Post by jvierra »

Also consider using a workflow as it can execute a number of items in parallel and execute new items as threads become available.

With a workflow you can set the concurrency and max pool size. The workflow then handles all queuing of tasks.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked