Class: Gru::Adapters::RedisAdapter
- Inherits:
-
Object
- Object
- Gru::Adapters::RedisAdapter
- Defined in:
- lib/gru/adapters/redis_adapter.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #expire_workers ⇒ Object
-
#initialize(client, settings) ⇒ RedisAdapter
constructor
A new instance of RedisAdapter.
- #provision_workers ⇒ Object
- #release_workers ⇒ Object
- #set_worker_counts ⇒ Object
Constructor Details
#initialize(client, settings) ⇒ RedisAdapter
Returns a new instance of RedisAdapter.
8 9 10 11 |
# File 'lib/gru/adapters/redis_adapter.rb', line 8 def initialize(client,settings) @client = client @settings = settings end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/gru/adapters/redis_adapter.rb', line 6 def client @client end |
Instance Method Details
#expire_workers ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gru/adapters/redis_adapter.rb', line 35 def expire_workers removable = {} workers = max_host_workers workers.each do |worker, count| removable[worker] = with_worker_counts(worker,count) do |total| if expire_worker?(worker) total -= 1 if expire_worker(worker) end total end end removable end |
#provision_workers ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gru/adapters/redis_adapter.rb', line 21 def provision_workers available = {} workers = max_host_workers workers.each do |worker, count| available[worker] = with_worker_counts(worker,count) do |total| if reserve_worker?(worker) total += 1 if reserve_worker(worker) end total end end available end |
#release_workers ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gru/adapters/redis_adapter.rb', line 49 def release_workers workers = max_host_workers workers.keys.each do |worker| host_running_count = local_running_count(worker) running_count = host_running_count global_running_count = host_running_count host_running_count.times do if global_running_count > 0 global_running_count = (:hincrby, global_workers_running_key,worker,-1) end if running_count > 0 running_count = (:hincrby, host_workers_running_key,worker,-1) end end end (:del, host_workers_running_key) (:del, host_max_worker_key) end |
#set_worker_counts ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/gru/adapters/redis_adapter.rb', line 13 def set_worker_counts set_rebalance_flag(@settings.rebalance_flag) register_workers(@settings.host_maximums) set_max_worker_counts(@settings.host_maximums) register_global_workers(@settings.cluster_maximums) set_max_global_worker_counts(@settings.cluster_maximums) end |