Module: TwitterRetry::Retryable

Included in:
TwitterRetry
Defined in:
lib/twitter_retry/retryable.rb

Instance Method Summary collapse

Instance Method Details

#ignorable?(error) ⇒ Boolean

whether ignorable error

Parameters:

  • error (Exception)

Returns:

  • (Boolean)


38
39
40
# File 'lib/twitter_retry/retryable.rb', line 38

def ignorable?(error)
  match_any_error?(error, TwitterRetry.config.ignorable_errors)
end

#retryable?(error) ⇒ Boolean

whether retryable error

Parameters:

  • error (Exception)

Returns:

  • (Boolean)


32
33
34
# File 'lib/twitter_retry/retryable.rb', line 32

def retryable?(error)
  match_any_error?(error, TwitterRetry.config.retryable_errors)
end

#suspended?(error) ⇒ Boolean

whether suspended user error

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/twitter_retry/retryable.rb', line 43

def suspended?(error)
  error.is_a?(Twitter::Error::Forbidden) &&
    error.message.include?("Your account is suspended and is not permitted to access this feature.")
end

#with_handingtrue, false

retry when error occurred matched with Config#retryable_errors

Returns:

  • (true)

    successful

  • (false)

    error is ignored (ex. Twitter::Error::Forbidden)

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/twitter_retry/retryable.rb', line 9

def with_handing
  retry_count = 0

  begin
    yield

  rescue => error
    return false               if ignorable?(error)
    raise SuspendedError       if suspended?(error)
    raise CannotRetryableError unless retryable?(error)
    raise RetryOverError       unless retry_count < TwitterRetry.config.max_retry_count

    retry_count += 1
    sleep(TwitterRetry.config.sleep_second)
    retry
  end

  # successful
  true
end