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