pebbles-river 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bc47f2039f74ecd2da833ce7c18e8335503e845
4
+ data.tar.gz: c67d6c720fe6e37e978ee2c3d0029cf6d6947ce6
5
+ SHA512:
6
+ metadata.gz: 9bafbd8b49a3f568e85c6a682d32d9c92813b31b4217751cad7733a44b55fc73cfc408912c02adef1531902be4adfd0e832774fd441cca56a0af07834fd2fce6
7
+ data.tar.gz: 4d1733af9cde03f3ed7f3565584c6ba20f84b89eb8fb9f35e1790026996f26e97e3cdf9784c390dd61b20209e4ceeb19d719c047fd7f048cf995d47930808619
@@ -13,9 +13,9 @@ module Pebbles
13
13
  options.assert_valid_keys(:logger, :pid_file, :worker_count, :worker)
14
14
 
15
15
  @worker_count = options[:worker_count] || 1
16
-
17
16
  @prefork_pools = []
18
17
  @worker_modules = []
18
+ @recovering = true
19
19
  end
20
20
 
21
21
  def start_workers
@@ -23,11 +23,13 @@ module Pebbles
23
23
  raise ConfigurationError.new("No listeners configured")
24
24
  end
25
25
 
26
- @worker_modules.each do |min_worker_count, m|
27
- @prefork_pools.push(
28
- Servolux::Prefork.new(
29
- min_workers: min_worker_count,
30
- module: m))
26
+ @worker_modules.each do |name, min_worker_count, m|
27
+ if min_worker_count > 0
28
+ prefork = Servolux::Prefork.new(min_workers: min_worker_count, module: m)
29
+ @prefork_pools.push([name, prefork])
30
+ else
31
+ logger.info "[#{name}] Workers disabled"
32
+ end
31
33
  end
32
34
  end
33
35
 
@@ -53,15 +55,17 @@ module Pebbles
53
55
  end
54
56
  })
55
57
 
56
- process_name = "#{@name}: queue worker: #{queue_spec[:name]}"
58
+ name = queue_spec[:name]
59
+
60
+ process_name = "#{@name}: queue worker: #{name}"
57
61
  logger = @logger
58
62
  worker_count = worker_options[:worker_count] || @worker_count
59
63
 
60
- @worker_modules.push([worker_count, Module.new {
64
+ @worker_modules.push([name, worker_count, Module.new {
61
65
  define_method :execute do
62
66
  $0 = process_name
63
67
  trap('TERM') do
64
- logger.info "Worker received TERM"
68
+ logger.info "[#{name}] Worker received TERM, stopping"
65
69
  worker.stop
66
70
  exit(0)
67
71
  end
@@ -72,11 +76,12 @@ module Pebbles
72
76
 
73
77
  # From Servolux::Server
74
78
  def before_starting
75
- $0 = "#{name}: master"
79
+ $0 = "#{self.name}: master"
76
80
 
77
81
  logger.info "Starting workers"
78
- @prefork_pools.each do |prefork|
79
- prefork.start(1)
82
+ @prefork_pools.each do |name, prefork|
83
+ logger.info "[#{name}] Starting workers"
84
+ prefork.ensure_worker_pool_size
80
85
  end
81
86
  end
82
87
 
@@ -92,9 +97,7 @@ module Pebbles
92
97
 
93
98
  # From Servolux::Server
94
99
  def run
95
- @prefork_pools.each do |prefork|
96
- prefork.ensure_worker_pool_size
97
- end
100
+ ensure_workers
98
101
  rescue => e
99
102
  if logger.respond_to? :exception
100
103
  logger.exception(e)
@@ -106,12 +109,51 @@ module Pebbles
106
109
 
107
110
  private
108
111
 
112
+ def ensure_workers
113
+ complete = true
114
+ @prefork_pools.each do |name, prefork|
115
+ if prefork.below_minimum_workers?
116
+ complete = false
117
+ else
118
+ had_workers = true
119
+ end
120
+
121
+ prefork.prune_workers
122
+
123
+ if had_workers and prefork.below_minimum_workers?
124
+ logger.error "[#{name}] One or more worker died"
125
+ end
126
+
127
+ while prefork.below_minimum_workers? do
128
+ @recovering = true
129
+ logger.info "[#{name}] Too few workers (" \
130
+ "#{prefork.live_worker_count} alive, #{prefork.dead_worker_count} dead), spawning another"
131
+ prefork.add_workers(1)
132
+ end
133
+ end
134
+
135
+ if @recovering and complete
136
+ @recovering = false
137
+ logger.info "All workers up"
138
+ end
139
+ end
140
+
109
141
  def shutdown_workers
110
- logger.info "Shutting down all workers"
111
- @prefork_pools.each(&:stop)
142
+ logger.info "Telling all workers to shut down"
143
+ @prefork_pools.each do |name, prefox|
144
+ prefox.stop
145
+ end
146
+
147
+ last_logged_time = Time.now
112
148
  loop do
113
- break if @prefork_pools.all? { |prefork| prefork.live_worker_count <= 0 }
114
- logger.info "Waiting for workers to quit"
149
+ count = @prefork_pools.inject(0) { |sum, (name, prefork)| sum + prefork.live_worker_count }
150
+ break if count == 0
151
+
152
+ if Time.now - last_logged_time > 5
153
+ logger.info "Still waiting for #{count} workers to quit..."
154
+ last_logged_time = Time.now
155
+ end
156
+
115
157
  sleep 0.25
116
158
  end
117
159
  end
@@ -1,5 +1,5 @@
1
1
  module Pebbles
2
2
  module River
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -119,7 +119,7 @@ module Pebbles
119
119
 
120
120
  def process_next
121
121
  with_exceptions do
122
- queue.pop(ack: true) do |delivery_info, properties, content|
122
+ queue.pop(manual_ack: true) do |delivery_info, properties, content|
123
123
  if delivery_info
124
124
  process_message(delivery_info, properties, content)
125
125
  return true
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_runtime_dependency 'pebblebed', '~> 0.3.0'
23
+ spec.add_runtime_dependency 'pebblebed', '>= 0.3.0'
24
24
  spec.add_runtime_dependency 'bunny', '= 1.6.0.rc2'
25
25
  spec.add_runtime_dependency 'activesupport', '>= 3.0'
26
26
  spec.add_runtime_dependency 'servolux', '~> 0.10'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebbles-river
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexander Staubo
@@ -10,28 +9,25 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-11-11 00:00:00.000000000 Z
12
+ date: 2015-04-15 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: pebblebed
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: 0.3.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ~>
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: 0.3.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: bunny
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - '='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - '='
45
40
  - !ruby/object:Gem::Version
@@ -47,113 +42,99 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: activesupport
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
48
  version: '3.0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - ">="
61
54
  - !ruby/object:Gem::Version
62
55
  version: '3.0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: servolux
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ~>
60
+ - - "~>"
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0.10'
71
63
  type: :runtime
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ~>
67
+ - - "~>"
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0.10'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: mercenary
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ~>
74
+ - - "~>"
85
75
  - !ruby/object:Gem::Version
86
76
  version: 0.3.3
87
77
  type: :runtime
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ~>
81
+ - - "~>"
93
82
  - !ruby/object:Gem::Version
94
83
  version: 0.3.3
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: rspec
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ~>
88
+ - - "~>"
101
89
  - !ruby/object:Gem::Version
102
90
  version: '3.0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ~>
95
+ - - "~>"
109
96
  - !ruby/object:Gem::Version
110
97
  version: '3.0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: bundler
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ~>
102
+ - - "~>"
117
103
  - !ruby/object:Gem::Version
118
104
  version: '1.5'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ~>
109
+ - - "~>"
125
110
  - !ruby/object:Gem::Version
126
111
  version: '1.5'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: rake
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - ">="
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - ">="
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: simplecov
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - ">="
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - ">="
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  description: Implements an event river mechanism for Pebblebed.
@@ -163,7 +144,7 @@ executables: []
163
144
  extensions: []
164
145
  extra_rdoc_files: []
165
146
  files:
166
- - .gitignore
147
+ - ".gitignore"
167
148
  - Gemfile
168
149
  - LICENSE.txt
169
150
  - README.md
@@ -189,27 +170,26 @@ files:
189
170
  homepage: ''
190
171
  licenses:
191
172
  - MIT
173
+ metadata: {}
192
174
  post_install_message:
193
175
  rdoc_options: []
194
176
  require_paths:
195
177
  - lib
196
178
  required_ruby_version: !ruby/object:Gem::Requirement
197
- none: false
198
179
  requirements:
199
- - - ! '>='
180
+ - - ">="
200
181
  - !ruby/object:Gem::Version
201
182
  version: '0'
202
183
  required_rubygems_version: !ruby/object:Gem::Requirement
203
- none: false
204
184
  requirements:
205
- - - ! '>='
185
+ - - ">="
206
186
  - !ruby/object:Gem::Version
207
187
  version: '0'
208
188
  requirements: []
209
189
  rubyforge_project:
210
- rubygems_version: 1.8.23.2
190
+ rubygems_version: 2.2.2
211
191
  signing_key:
212
- specification_version: 3
192
+ specification_version: 4
213
193
  summary: Implements an event river mechanism for Pebblebed.
214
194
  test_files:
215
195
  - spec/lib/river_spec.rb
@@ -217,3 +197,4 @@ test_files:
217
197
  - spec/lib/subscription_spec.rb
218
198
  - spec/lib/worker_spec.rb
219
199
  - spec/spec_helper.rb
200
+ has_rdoc: