$pm->run_on_finish(sub {
my ($pid, $exit_code, $ident) = @_;
my ($action, $host) = $ident =~ /^(.*?) on (.*)/s;
printf "run_on_finish: %s (pid: %s exited with code: %s\n",
$ident, $pid, $exit_code;
insert_into_db(\$dbh, $host, $action, $exit_code);
});
####
for my $host (@hosts) {
if (!$pm->start("cmd1 on $host")) {
exec(@cmd1, $host);
print(STDERR "cmd1 exec failed: $!\n");
_exit($!);
}
if (!$pm->start("cmd2 on $host")) {
exec(@cmd2, $host);
print(STDERR "cmd2 exec failed: $!\n");
_exit($!);
}
}
####
for my $host (@hosts) {
for (
[ cmd1 => \@cmd1 ],
[ cmd2 => \@cmd2 ],
) {
my ($action, $cmd) = @$_;
$pm->start("$action on $host") and next;
exec(@$cmd, $host);
print(STDERR "$action exec failed: $!\n");
_exit($!);
}
}