NAME

HealthCheck::Parallel - A HealthCheck that uses parallelization for running checks

VERSION

version v0.0.2

SYNOPSIS

use HealthCheck::Parallel;

my $hc = HealthCheck::Parallel->new(
    max_procs  => 4,      # default
    tempdir    => '/tmp', # override Parallel::ForkManager default
    child_init => sub { warn "Will run at start of child process check" },
    checks     => [
        sub { sleep 5; return { id => 'slow1', status => 'OK' } },
        sub { sleep 5; return { id => 'slow2', status => 'OK' } },
    ],
);

# Takes 5 seconds to run both checks instead of 10.
my $res = $hc->check;

# These checks will not use parallelization.
$res = $hc->check( max_procs => 0 );

DESCRIPTION

This library inherits HealthCheck so that the provided checks are run in parallel.

METHODS

new

Overrides the "new" in HealthCheck constructor to additionally allow a "max_procs" argument for the maximum number of checks/processes to run in parallel.

ATTRIBUTES

max_procs

A positive integer specifying the maximum number of processes that should be run in parallel when executing the checks. No parallelization will be used unless given a value that is greater than 1. Defaults to 4.

child_init

An optional coderef which will be run when the child process of a check is created. A possible important use case is making sure child processes don't try to make use of STDOUT if these checks are running under FastCGI envrionment:

my $hc = HealthCheck::Parallel->new(
    child_init => sub {
        untie *STDOUT;
        { no warnings; *FCGI::DESTROY = sub {}; }
    },
);

tempdir

Sets the tempdir value to use in Parallel::ForkManager for IPC.

DEPENDENCIES

SEE ALSO

AUTHOR

Grant Street Group <developers@grantstreet.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2023 by Grant Street Group.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)