Module: TwitterRetry::Retryable
- Included in:
- TwitterRetry
- Defined in:
- lib/twitter_retry/retryable.rb
Instance Method Summary collapse
-
#ignorable?(error) ⇒ Boolean
whether ignorable error.
-
#retryable?(error) ⇒ Boolean
whether retryable error.
-
#suspended?(error) ⇒ Boolean
whether suspended user error.
-
#with_handing ⇒ true, false
retry when error occurred matched with #RETRYABLE_ERRORS.
Instance Method Details
#ignorable?(error) ⇒ Boolean
whether ignorable error
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
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
43 44 45 46 |
# File 'lib/twitter_retry/retryable.rb', line 43 def suspended?(error) error.is_a?(Twitter::Error::Forbidden) && error..include?("Your account is suspended and is not permitted to access this feature.") end |
#with_handing ⇒ true, false
retry when error occurred matched with #RETRYABLE_ERRORS
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 |