| Class | Beetle::DeduplicationStore |
| In: |
lib/beetle/deduplication_store.rb
|
| Parent: | Object |
The deduplication store is used internally by Beetle::Client to store information on the status of message processing. This includes:
It also provides a method to garbage collect keys for expired messages.
| KEY_SUFFIXES | = | [:status, :ack_count, :timeout, :delay, :attempts, :exceptions, :mutex, :expires] | list of key suffixes to use for storing values in Redis. |
# File lib/beetle/deduplication_store.rb, line 16
16: def initialize(config = Beetle.config)
17: @config = config
18: @current_master = nil
19: @last_time_master_file_changed = nil
20: end
garbage collect keys in Redis (always assume the worst!)
# File lib/beetle/deduplication_store.rb, line 53
53: def garbage_collect_keys(now = Time.now.to_i)
54: keys = redis.keys("msgid:*:expires")
55: threshold = now + @config.gc_threshold
56: keys.each do |key|
57: expires_at = redis.get key
58: if expires_at && expires_at.to_i < threshold
59: msg_id = msg_id(key)
60: redis.del(keys(msg_id))
61: end
62: end
63: end
get the Redis instance
# File lib/beetle/deduplication_store.rb, line 23
23: def redis
24: redis_master_source = @config.redis_server =~ /^\S+\:\d+$/ ? "server_string" : "master_file"
25: _eigenclass_.class_eval "def redis\nredis_master_from_\#{redis_master_source}\nend\n", __FILE__, __LINE__
26: redis
27: end
set current redis master instance (as specified in the Beetle::Configuration)
# File lib/beetle/deduplication_store.rb, line 132
132: def redis_master_from_server_string
133: @current_master ||= Redis.from_server_string(@config.redis_server, :db => @config.redis_db)
134: end
set current redis master from server:port string contained in the redis master file
# File lib/beetle/deduplication_store.rb, line 150
150: def set_current_redis_master_from_master_file
151: @last_time_master_file_changed = File.mtime(@config.redis_server)
152: server_string = read_master_file
153: @current_master = !server_string.blank? ? Redis.from_server_string(server_string, :db => @config.redis_db) : nil
154: end