NAME

Twitter::API::Trait::RetryOnError - Automatically retry API calls on error

VERSION

version 0.0110

SYNOPSIS

use Twitter::API;

my $client = Twitter::API->new_with_options(
    traits => [ qw/ApiMethods RetryOnError/ ],
    %other_optons
);

my $statuses = $client->home_timeline;

DESCRIPTION

With this trait applied, Twitter::API automatically retries API calls that result in an HTTP status code of 500 or greater. These errors often indicate a temporary problem, either on Twitter's end, locally, or somewhere in between. By default, it retries up to 5 times. The initial retry is delayed by 250ms. Additional retries double the delay time until the maximum delay is reached (default: 4 seconds). Twitter::API throws a Twitter::API::Error exception when it receives a permanent error (HTTP status code below 500), or the maximum number of retries has been reached.

For non-blocking applications, set a suitable retry_delay_code callback. This attribute can also be used to provided retry logging.

ATTRIBUTES

initial_retry_delay

Amount of time to delay before the initial retry. Specified in fractional seconds. Default: 0.25 (250ms).

max_retry_delay

Maximum delay between retries, specified in fractional seconds. Default: 4.0.

retry_delay_multiplier

After the initial delay, the delay time is multiplied by this factor to progressively back off allowing more time for the transient condition to resolve. However, the delay never exceeds max_retry_delay. Default: 2.0.

max_retries

Maximum number of times to retry on error. Default: 5.

retry_delay_code

A coderef, called to implement a delay. It takes a single parameter, the number of seconds to delay. E.g., 0.25. The default implementation is simply:

sub { Time::HiRes::sleep(shift) }

AUTHOR

Marc Mims <marc@questright.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015-2016 by Marc Mims.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.