Action-CircuitBreaker

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    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.

README  view on Meta::CPAN

 max_retries_number

      ro, int, optional

    Maximum number of retries before opening circuit.

 open_time

      ro, int, optional

    Time in number of seconds to open the circuit for after
    max_retries_number have failed.

METHODS

 run

    Does the following:

    step 1

lib/Action/CircuitBreaker.pm  view on Meta::CPAN

    default => sub { 0 },
    init_arg => undef,
);


sub run {
    my ($self, $attempt_code) = @_;

    if (my $timestamp = $self->_circuit_open_until) {
        # we can't execute until the timestamp has done
        my ($seconds, $microseconds) = gettimeofday;
        $seconds * 1000 + int($microseconds / 1000) >= $timestamp
          or die 'The circuit is open and cannot be executed.';
        $self->_circuit_open_until(0);
        $self->has_on_circuit_close
          and $self->on_circuit_close->();
    }

    my $error;
    my @attempt_result;
    my $attempt_result;
    my $wantarray;

lib/Action/CircuitBreaker.pm  view on Meta::CPAN


    my $h = { action_retry => $self,
              attempt_result => ( $wantarray ? \@attempt_result : $attempt_result ),
              attempt_parameters => \@_,
            };


    if ($self->error_if_code->($error, $h)) {
        $self->_current_retries_number($self->_current_retries_number + 1);
        if ($self->_current_retries_number >= $self->max_retries_number) {
            my ($seconds, $microseconds) = gettimeofday;
            my $open_until = ($self->open_time * 1000) + ($seconds * 1000 + int($microseconds / 1000));
            $self->_circuit_open_until($open_until);
            $self->has_on_circuit_open
              and $self->on_circuit_open->();
        }
        die $error;
    } else {
        return $h->{attempt_result};
    }
}

lib/Action/CircuitBreaker.pm  view on Meta::CPAN


=over

=item * 

as first argument, a scalar which is the value of any exception that were
raised by the C<$attempt_code>. Otherwise, undef.

=item *

as second argument, a HashRef, which contains these keys:

=back

=over

=item action_retry

it's a reference on the ActionRetry instance. That way you can have access to
the other attributes.

lib/Action/CircuitBreaker.pm  view on Meta::CPAN

=head2 max_retries_number

  ro, int, optional

Maximum number of retries before opening circuit.

=head2 open_time

  ro, int, optional

Time in number of seconds to open the circuit for after C<max_retries_number> have failed.

=head1 METHODS

=head2 run

Does the following:

=over

=item step 1

t/00-report-prereqs.t  view on Meta::CPAN

}
else {
    $cpan_meta_error = $@;    # capture error from CPAN::Meta->load_file($source)
    $source = 'static metadata';
}

my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;

# Add static includes into a fake section
for my $mod (@include) {
    $req_hash->{other}{modules}{$mod} = 0;
}

for my $phase ( qw(configure build test runtime develop other) ) {
    next unless $req_hash->{$phase};
    next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});

    for my $type ( qw(requires recommends suggests conflicts modules) ) {
        next unless $req_hash->{$phase}{$type};



( run in 1.007 second using v1.01-cache-2.11-cpan-39bf76dae61 )