From 82bfec6e44209b4e1bce115e4adca62d0fffb279 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 21 Mar 2024 21:00:12 -0700 Subject: Exit if any of the parallel processes return an error --- lib/MGA/Advisories.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm index dbb7408..4663eb6 100644 --- a/lib/MGA/Advisories.pm +++ b/lib/MGA/Advisories.pm @@ -621,6 +621,14 @@ sub process_template { # Max 10 processes for processing templates my $pm = Parallel::ForkManager->new(10); +$pm->run_on_finish(\¶llel_finish); +my $parallelerror = 0; + +# Store error flag from forked process +sub parallel_finish { + my ($pid, $exit_code, $ident) = @_; + $parallelerror |= $exit_code; +} # Run process_template in its own process. The process creation overhead is # high, so this only makes sense for templates that interate over all or most @@ -633,9 +641,10 @@ sub parallel_process_template { } } -# Wait for all processes to finish +# Wait for all processes to finish & die if any returned an error sub parallel_complete { $pm->wait_all_children; + die "Error writing output" if $parallelerror; } sub output_pages { -- cgit v1.2.1