gru 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2002057fd3f7622545619c577dd9116f5efafea3
4
- data.tar.gz: c1eec4430b446adbf7f92bd3f009ef3b9f2722c6
3
+ metadata.gz: 4e79626380c84c31c2f12ca59d88a1b36dd3294f
4
+ data.tar.gz: 9e5903acfec6906910e8fd6050dd2d83d40e60de
5
5
  SHA512:
6
- metadata.gz: e3f077b9c3f83e60a08f733a094d8e1382025dbce996ee1808222fccd43131a892ccbb36298c4828e78ce29d1055f10480f13fa8213f333fcd21e6223e782e5b
7
- data.tar.gz: e090daf35b63bdab1c4920008125b9458958d73160026b833e8484e50d4cf4753075c73455e363987d796b64a3bc63a84543904cc86be8dc333ec430ab9ede7d
6
+ metadata.gz: 65c48ef82fe013ba1ef8735c41cfe9834a73a824c3aa67c3ca4f5ab4ca9d0e1ac9d25b54199c032d46083f97698be3dc8e53dfd32e64c90e9170b0068b5934ff
7
+ data.tar.gz: 2d4d11082bf6c6ac06b6e53ca5dbbeaa7d1ddc029553a6aac7335b7a9856a35e5051bb1f3028a6b8090464888fe670759cc2c732575d5a66da96af0deacd34a6
@@ -12,6 +12,7 @@ module Gru
12
12
 
13
13
  def set_worker_counts
14
14
  set_rebalance_flag(@settings.rebalance_flag)
15
+ set_presume_host_dead_after(@settings.presume_host_dead_after)
15
16
  release_workers
16
17
  register_workers(@settings.host_maximums)
17
18
  set_max_worker_counts(@settings.host_maximums)
@@ -66,6 +67,18 @@ module Gru
66
67
  send_message(:del, host_max_worker_key)
67
68
  end
68
69
 
70
+ def release_presumed_dead_workers
71
+ presumed_dead_cluster_members.each_pair do |hostname,timestamp|
72
+ lock_key = "#{gru_key}:removing_dead_host:#{hostname}"
73
+ if send_message(:setnx,lock_key,Time.now.to_i)
74
+ remove_dead_host_workers_from_counts(hostname)
75
+ send_message(:del,lock_key)
76
+ return true
77
+ end
78
+ false
79
+ end
80
+ end
81
+
69
82
  private
70
83
 
71
84
  def register_workers(workers)
@@ -89,6 +102,10 @@ module Gru
89
102
  send_message(:set,"#{gru_key}:rebalance",rebalance)
90
103
  end
91
104
 
105
+ def set_presume_host_dead_after(seconds)
106
+ send_message(:set,"#{gru_key}:presume_host_dead_after",seconds)
107
+ end
108
+
92
109
  def register_worker(worker,count)
93
110
  send_message(:hsetnx,host_workers_running_key,worker,count)
94
111
  end
@@ -105,6 +122,15 @@ module Gru
105
122
  send_message(:hset,global_max_worker_key,worker,count)
106
123
  end
107
124
 
125
+ def remove_dead_host_workers_from_counts(hostname)
126
+ workers_running_on_dead_host = send_message(:hgetall, "#{gru_key}:#{hostname}:workers_running")
127
+ workers_running_on_dead_host.each_pair do |worker_name, count|
128
+ send_message(:hincrby,"#{gru_key}:#{hostname}:workers_running",worker_name,Integer(count)*-1)
129
+ send_message(:hincrby,global_workers_running_key,worker_name,Integer(count)*-1)
130
+ end
131
+ send_message(:hdel,resque_cluster_pings_key,hostname)
132
+ end
133
+
108
134
  def reset_removed_global_worker_counts(workers)
109
135
  global_max = max_host_workers
110
136
  global_max.each_pair do |worker, count|
@@ -145,6 +171,10 @@ module Gru
145
171
  send_message(:hgetall,global_max_worker_key)
146
172
  end
147
173
 
174
+ def resque_cluster_members
175
+ send_message(:hgetall, resque_cluster_pings_key)
176
+ end
177
+
148
178
  def reserve_worker?(worker)
149
179
  host_running,global_running,host_max,global_max = worker_counts(worker)
150
180
  result = false
@@ -176,6 +206,10 @@ module Gru
176
206
  end
177
207
  end
178
208
 
209
+ def presumed_dead_cluster_members
210
+ resque_cluster_members.select{ |hostname, timestamp| Time.parse(timestamp).to_i + presume_host_dead_after < Time.now.to_i}
211
+ end
212
+
179
213
  def local_running_count(worker)
180
214
  send_message(:hget,host_workers_running_key,worker).to_i
181
215
  end
@@ -194,6 +228,11 @@ module Gru
194
228
  send_message(:get,"#{gru_key}:rebalance") == "true"
195
229
  end
196
230
 
231
+ def presume_host_dead_after
232
+ dead_after_number_of_seconds = send_message(:get,"#{gru_key}:presume_host_dead_after").to_i
233
+ dead_after_number_of_seconds > 0 ? dead_after_number_of_seconds : 120
234
+ end
235
+
197
236
  def host_max_worker_key
198
237
  "#{host_key}:max_workers"
199
238
  end
@@ -222,6 +261,10 @@ module Gru
222
261
  "GRU:#{@settings.environment_name}:#{@settings.cluster_name}"
223
262
  end
224
263
 
264
+ def resque_cluster_pings_key
265
+ "resque:cluster:#{@settings.cluster_name}:#{@settings.environment_name}:pings"
266
+ end
267
+
225
268
  def hostname
226
269
  @hostname ||= Socket.gethostname
227
270
  end
@@ -3,7 +3,7 @@ require 'gru/adapters/redis_adapter'
3
3
 
4
4
  module Gru
5
5
  class Configuration
6
- attr_reader :cluster_maximums, :host_maximums, :rebalance_flag, :adapter, :cluster_name, :environment_name
6
+ attr_reader :cluster_maximums, :host_maximums, :rebalance_flag, :adapter, :cluster_name, :environment_name, :presume_host_dead_after
7
7
  def initialize(settings)
8
8
  @host_maximums = settings.delete(:host_maximums) || settings.delete(:cluster_maximums)
9
9
  @cluster_maximums = settings.delete(:cluster_maximums) || @host_maximums
@@ -11,6 +11,7 @@ module Gru
11
11
  @cluster_name = settings.delete(:cluster_name) || 'default'
12
12
  @environment_name = settings.delete(:environment_name) || 'default'
13
13
  client = initialize_client(settings.delete(:client_settings))
14
+ @presume_host_dead_after = settings.delete(:presume_host_dead_after)
14
15
  @adapter = Gru::Adapters::RedisAdapter.new(client,self)
15
16
  if @cluster_maximums.nil?
16
17
  raise ArgumentError "Need at least a cluster configuration"
@@ -1,3 +1,3 @@
1
1
  module Gru
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -6,6 +6,10 @@ module Gru
6
6
  @adapter = adapter
7
7
  end
8
8
 
9
+ def expire_dead_cluster_members
10
+ @adapter.release_presumed_dead_workers
11
+ end
12
+
9
13
  def register_workers
10
14
  @adapter.set_worker_counts
11
15
  end
@@ -20,6 +24,7 @@ module Gru
20
24
 
21
25
  def adjust_workers
22
26
  result = {}
27
+ expire_dead_cluster_members
23
28
  add = provision_workers
24
29
  remove = expire_workers
25
30
  keys = add.keys + remove.keys
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Gillis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - '>'
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">"
24
+ - - '>'
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">"
73
+ - - '>'
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">"
80
+ - - '>'
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: awesome_print
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">"
87
+ - - '>'
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">"
94
+ - - '>'
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.0'
97
97
  description: This is a worker/minion manager using different atomic data stores.
@@ -101,7 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - ".gitignore"
104
+ - .gitignore
105
105
  - Gemfile
106
106
  - LICENSE.txt
107
107
  - README.md
@@ -125,20 +125,21 @@ require_paths:
125
125
  - lib
126
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - ">="
128
+ - - '>='
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - ">="
133
+ - - '>='
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.4.5
138
+ rubygems_version: 2.4.4
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: An atomic worker/minion manager.
142
142
  test_files:
143
143
  - spec/gru/adapters/redis_adapter_spec.rb
144
144
  - spec/gru/worker_manager_spec.rb
145
+ has_rdoc: