Action-CircuitBreaker
view release on metacpan or search on metacpan
NAME
Action::CircuitBreaker - Module to try to perform an action, with an
option to suspend execution after a number of failures.
VERSION
version 0.1
SYNOPSIS
# Will execute the code, as the circuit will be closed by default.
# OO interface
use Action::CircuitBreaker;
Action::CircuitBreaker->new()->run(sub { do_stuff; });
ATTRIBUTES
error_if_code
ro, CodeRef
The code to run to check if the error should count towards the circuit
breaker. It defaults to:
# Returns true if there were an exception evaluating to something true
sub { $_[0] }
It will be given these arguments:
* as first argument, a scalar which is the value of any exception
that were raised by the $attempt_code. Otherwise, undef.
* as second argument, a HashRef, which contains these keys:
action_retry
it's a reference on the ActionRetry instance. That way you can have
access to the other attributes.
attempt_result
It's a scalar, which is the result of $attempt_code. If $attempt_code
returned a list, then the scalar is the reference on this list.
attempt_parameters
It's the reference on the parameters that were given to
$attempt_code.
error_if_code return value will be interpreted as a boolean : true
return value means the execution of $attempt_code was a failure and
should count towards breaking the ciruit. False means it went well.
Here is an example of code that gets the arguments properly:
my $action = Action::CircuitBreaker->new(
error_if_code => sub {
my ($error, $h) = @_;
my $attempt_code_result = $h->{attempt_result};
my $attempt_code_params = $h->{attempt_parameters};
my @results = @$attempt_code_result;
# will contains (2, 4);
my @original_parameters = @$attempt_code_params;
# will contains (1, 2);
}
);
my @results = $action->run(sub { print @_; }, 1, 2);
on_failure_code
ro, CodeRef, optional
If given, will be executed when an execution fails.
It will be given the same arguments as error_if_code. See error_if_code
for their descriptions
on_circuit_open
ro, CodeRef, optional
If given, will be executed the circuit gets opened.
It will be given the same arguments as error_if_code. See error_if_code
for their descriptions
on_circuit_close
( run in 0.969 second using v1.01-cache-2.11-cpan-d80b1682f3f )