Class: Gru::Adapters::RedisAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/gru/adapters/redis_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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_workersObject



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_workersObject



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_workersObject



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 = send_message(:hincrby, global_workers_running_key,worker,-1)
      end
      if running_count > 0
        running_count = send_message(:hincrby, host_workers_running_key,worker,-1)
      end
    end
  end
  send_message(:del, host_workers_running_key)
  send_message(:del, host_max_worker_key)
end

#set_worker_countsObject



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