use strict;
use warnings;
+use Osstest;
+use Osstest::Executive;
+
BEGIN {
use Exporter ();
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
cacheable_fn
cache_write_entry
cache_finish
+ parallel_by_fork
);
%EXPORT_TAGS = ();
print ::DEBUG " extra=$rows_extra\n";
}
+our %children;
+our $worst = 0;
+our $whoami;
+
+sub wait_for_max_children ($) {
+ my ($lim) = @_;
+ while (keys(%children) > $lim) {
+ $!=0; $?=0; my $got = wait;
+ die "$! $got $?" unless exists $children{$got};
+ my $host = $children{$got};
+ delete $children{$got};
+ $worst = $? if $? > $worst;
+ if ($?) {
+ print STDERR $whoami."[$$]: [$got] failed for $host: $?\n";
+ } else {
+ print ::DEBUG "REAPED [$got] $host\n";
+ }
+ }
+}
+
+sub parallel_by_fork ($$$$) {
+ my ($set_whoami, $maxjobs, $tasks, $fn) = @_;
+ # does $fn->($_) foreach @$tasks
+ # but in parallal and then exits.
+ # entries in @$taskarray should be suitable for print in messages.
+ # db is reopened in each child.
+
+ $whoami = $set_whoami;
+ undef $dbh_tests;
+
+ foreach my $task (@$tasks) {
+ wait_for_max_children($maxjobs);
+
+ my $pid = fork // die $!;
+ if (!$pid) {
+ opendb_tests();
+ $fn->($task);
+ exit 0;
+ }
+ print ::DEBUG "SPAWNED [$pid] $task\n";
+ $children{$pid} = $task;
+ }
+
+ wait_for_max_children(0);
+ exit $worst;
+}
+
1;
computeflightsrange();
});
-undef $dbh_tests;
-
-our %children;
-our $worst = 0;
-
-sub wait_for_max_children ($) {
- my ($lim) = @_;
- while (keys(%children) > $lim) {
- $!=0; $?=0; my $got = wait;
- die "$! $got $?" unless exists $children{$got};
- my $host = $children{$got};
- delete $children{$got};
- $worst = $? if $? > $worst;
- if ($?) {
- print STDERR "sg-report-flight[: [$got] failed for $host: $?\n";
- } else {
- print DEBUG "REAPED [$got] $host\n";
- }
- }
-}
-
-foreach my $host (sort keys %hosts) {
- wait_for_max_children($maxjobs);
-
- my $pid = fork // die $!;
- if (!$pid) {
- opendb_tests();
- cache_read_previous("$htmlout/$host.html") if $read_previous;
- db_retry($dbh_tests, [], sub {
- mainquery($host);
- reporthost $host;
- });
- exit(0);
- }
- print DEBUG "SPAWNED [$pid] $host\n";
- $children{$pid} = $host;
-}
-
-wait_for_max_children(0);
-exit $worst;
+parallel_by_fork('sg-report-flight', $maxjobs, [ sort keys %hosts ], sub {
+ my ($host) = @_;
+ cache_read_previous("$htmlout/$host.html") if $read_previous;
+ db_retry($dbh_tests, [], sub {
+ mainquery($host);
+ reporthost $host;
+ });
+ exit(0);
+});