Module: Hive::Retriable

Included in:
Broadcast, TransactionBuilder
Defined in:
lib/hive/mixins/retriable.rb

Constant Summary collapse

MAX_RETRY_COUNT =
30
MAX_RETRY_ELAPSE =
60
MAX_BACKOFF =
MAX_RETRY_ELAPSE / 4
RETRYABLE_EXCEPTIONS =
[
  NonCanonicalSignatureError, IncorrectRequestIdError,
  IncorrectResponseIdError, RemoteDatabaseLockError
]

Instance Method Summary collapse

Instance Method Details

#can_retry?(e = nil) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hive/mixins/retriable.rb', line 16

def can_retry?(e = nil)
  @retry_count ||= 0
  
  return false if @retry_count >= MAX_RETRY_COUNT
  
  @retry_count = if retry_reset?
    @first_retry_at = nil
  else
    @retry_count + 1
  end
  
  can_retry = case e
  when *RETRYABLE_EXCEPTIONS then true
  else; false
  end
  
  backoff if can_retry
  
  can_retry
end