Class: ZeevexCluster::Coordinator::BaseKeyValStore
- Inherits:
-
Object
- Object
- ZeevexCluster::Coordinator::BaseKeyValStore
show all
- Includes:
- Util::Logging
- Defined in:
- lib/zeevex_cluster/coordinator/base_key_val_store.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#logger
Constructor Details
Returns a new instance of BaseKeyValStore.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/zeevex_cluster/coordinator/base_key_val_store.rb', line 13
def initialize(options = {})
self.class.setup
@options = options
if (!options[:server] && !options[:client]) || !options[:expiration]
raise ArgumentError, "Must supply [:server or :client] and :expiration"
end
if options[:client]
@client = options[:client]
else
@server = options[:server]
@port = options[:port] || 11211
end
@expiration = options[:expiration] || 60
@logger = options[:logger]
@serializer = options[:serializer] || ZeevexCluster::Serializer::EDN.new
@retries = options.fetch(:retries, 20)
@retry_wait = options.fetch(:retry_wait, 2)
@retry_bo = options.fetch(:retry_bo, 1.5)
end
|
Class Method Details
.setup ⇒ Object
6
7
8
9
10
11
|
# File 'lib/zeevex_cluster/coordinator/base_key_val_store.rb', line 6
def self.setup
unless @setup
require 'zeevex_cluster/serializer/edn'
@setup = true
end
end
|
Instance Method Details
#with_connection_retry(method, options = {}, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/zeevex_cluster/coordinator/base_key_val_store.rb', line 42
def with_connection_retry(method, options = {}, *args, &block)
retry_left = options.fetch(:retries, @retries)
retry_wait = options.fetch(:retry_wait, @retry_wait)
begin
send "do_#{method}", *args, &block
rescue ZeevexCluster::Coordinator::ConnectionError
if retry_left > 0
logger.debug "retrying after #{retry_wait} seconds"
retry_left -= 1
sleep retry_wait
retry_wait = retry_wait * options.fetch('retry_bo', @retry_bo)
retry
else
logger.error 'Ran out of connection retries, re-raising'
raise
end
end
end
|