Class: Cequel::Metal::Policy::CassandraError::ClearAndRetryPolicy
- Inherits:
-
ErrorPolicyBase
- Object
- ErrorPolicyBase
- Cequel::Metal::Policy::CassandraError::ClearAndRetryPolicy
- Defined in:
- lib/cequel/metal/policy/cassandra_error.rb
Overview
Instance Attribute Summary collapse
-
#clear_before_retry ⇒ Object
readonly
Boolean if this policy clears connections before retry.
-
#max_retries ⇒ Object
readonly
Integer maximum number of retries to reconnect to Cassandra.
-
#retry_delay ⇒ Object
readonly
Float delay between retries to reconnect to Cassandra.
Instance Method Summary collapse
- #execute_stmt(keyspace) ⇒ Object
-
#initialize(options = {}) ⇒ ClearAndRetryPolicy
constructor
A new instance of ClearAndRetryPolicy.
Constructor Details
#initialize(options = {}) ⇒ ClearAndRetryPolicy
Returns a new instance of ClearAndRetryPolicy.
34 35 36 37 38 39 40 41 42 |
# File 'lib/cequel/metal/policy/cassandra_error.rb', line 34 def initialize( = {}) @max_retries = .fetch(:max_retries, 3) @retry_delay = .fetch(:retry_delay, 0.5) @clear_before_retry = !!.fetch(:clear_before_retry, true) if @retry_delay <= 0.0 raise ArgumentError, "The value for retry must be a positive number, not '#{@retry_delay}'" end end |
Instance Attribute Details
#clear_before_retry ⇒ Object (readonly)
Returns Boolean if this policy clears connections before retry.
33 34 35 |
# File 'lib/cequel/metal/policy/cassandra_error.rb', line 33 def clear_before_retry @clear_before_retry end |
#max_retries ⇒ Object (readonly)
Returns Integer maximum number of retries to reconnect to Cassandra.
29 30 31 |
# File 'lib/cequel/metal/policy/cassandra_error.rb', line 29 def max_retries @max_retries end |
#retry_delay ⇒ Object (readonly)
Returns Float delay between retries to reconnect to Cassandra.
31 32 33 |
# File 'lib/cequel/metal/policy/cassandra_error.rb', line 31 def retry_delay @retry_delay end |
Instance Method Details
#execute_stmt(keyspace) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cequel/metal/policy/cassandra_error.rb', line 44 def execute_stmt(keyspace) retries_remaining = max_retries begin yield rescue Cassandra::Errors::NoHostsAvailable, Cassandra::Errors::ExecutionError, Cassandra::Errors::TimeoutError => error raise error if retries_remaining == 0 sleep(retry_delay) keyspace.clear_active_connections! if clear_before_retry retries_remaining -= 1 retry end end |