0

I have several jobs that I would like to orchestrate and monitor in PowerShell. All these are -scriptblock Jobs so each are running in their own environment.

$Job_List = JobNum1, JobNum2, JobNum3, JobNum4, JobNum5
PS > Get-Job

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
--     ----            -------------   -----         -----------     --------             -------                  
1      JobNum1         BackgroundJob   Running       True            localhost             & $args[0] ; while($t...
3      JobNum2         BackgroundJob   Running       True            localhost             & $args[0] ; while($t...
5      JobNum3         BackgroundJob   Running       True            localhost             & $args[0] ; while($t...
7      JobNum4         BackgroundJob   Running       True            localhost             & $args[0] ; Send-Com...
9      JobNum5         BackgroundJob   Running       True            localhost             & $args[0] ; while($t...

Ideally, at the "same level" as my jobs (i.e. not something running my jobs as a ChildJobs, which is one of my fallback ideas), I would like to add a control job.

11     JobController   BackgroundJob   Running       True            localhost             & $args[0] ; while($t...

The control job would at regular interval parse my $Job_List, check the State of the job (i.e. running or failed in this basic example, but I actually need to do more) and re-launch any failed job, but not as a child item of JobController. I do not need help on the parsing logic, but rather on the way to orchestrate the solution.

Any idea on how to achieve this ?

One fall-back plan would be to launch all jobs JobNum1, JobNum2... as Child-Items of JobController, but tuning and debugging is going to be painful. I am also open to other solutions and smart ideas.

Thanks in advance !

Philippe

Philippe
  • 103
  • 1
  • 1
  • 8
  • Are those 5 jobs supposed to run like services (until you stop them yourself)? Also, I'm not really getting the issue with parent/child model. This way you can control children with get-job or events. Otherwise you still just watch those pids, just need to create custom code for watching (what's the benefit?) – Mike Twc Dec 04 '18 at 02:12
  • Hello Mike, Yes those jobs are supposed to run like services. My issue about parent/child model is that I will have to look at the errors in the childs as well. The benefit I view is that my jobs do not fail or get into some unexpected status for some reason (i.e. running from PS but with an issue within the job itself) – Philippe Dec 05 '18 at 10:41

0 Answers0