sensu 0.9.4.beta.1 → 0.9.4.beta.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu/client.rb CHANGED
@@ -37,8 +37,8 @@ module Sensu
37
37
 
38
38
  def setup_amqp
39
39
  @logger.debug('[amqp] -- connecting to rabbitmq')
40
- rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
41
- @amq = AMQP::Channel.new(rabbitmq)
40
+ @rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
41
+ @amq = AMQP::Channel.new(@rabbitmq)
42
42
  end
43
43
 
44
44
  def publish_keepalive
@@ -201,9 +201,13 @@ module Sensu
201
201
  @timers.each do |timer|
202
202
  timer.cancel
203
203
  end
204
- @logger.warn('[stop] -- unsubscribing from subscriptions')
205
- @check_request_queue.unsubscribe do
206
- stop_reactor
204
+ unless @rabbitmq.reconnecting?
205
+ @logger.warn('[stop] -- unsubscribing from subscriptions')
206
+ @check_request_queue.unsubscribe do
207
+ stop_reactor
208
+ end
209
+ else
210
+ EM::stop_event_loop
207
211
  end
208
212
  end
209
213
  end
data/lib/sensu/config.rb CHANGED
@@ -1,5 +1,3 @@
1
- require File.join(File.dirname(__FILE__), 'patches', 'ruby')
2
-
3
1
  require 'rubygems'
4
2
  require 'bundler'
5
3
  require 'bundler/setup'
@@ -14,6 +12,9 @@ require 'amqp'
14
12
  require 'cabin'
15
13
  require 'cabin/outputs/em/stdlib-logger'
16
14
 
15
+ require File.join(File.dirname(__FILE__), 'patches', 'ruby')
16
+ require File.join(File.dirname(__FILE__), 'patches', 'amqp')
17
+
17
18
  if ENV['RBTRACE']
18
19
  require 'rbtrace'
19
20
  end
@@ -0,0 +1,7 @@
1
+ module AMQP
2
+ module Client
3
+ def reconnecting?
4
+ @reconnecting || false
5
+ end
6
+ end
7
+ end
data/lib/sensu/server.rb CHANGED
@@ -48,8 +48,8 @@ module Sensu
48
48
 
49
49
  def setup_amqp
50
50
  @logger.debug('[amqp] -- connecting to rabbitmq')
51
- rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
52
- @amq = AMQP::Channel.new(rabbitmq)
51
+ @rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
52
+ @amq = AMQP::Channel.new(@rabbitmq)
53
53
  end
54
54
 
55
55
  def setup_keepalives
@@ -321,6 +321,18 @@ module Sensu
321
321
  end
322
322
  end
323
323
 
324
+ def resign_as_master(&block)
325
+ if @is_master
326
+ @redis.del('lock:master').callback do
327
+ @logger.warn('[master] -- resigned as master')
328
+ block.call if block
329
+ end
330
+ else
331
+ @logger.warn('[master] -- not currently master')
332
+ block.call if block
333
+ end
334
+ end
335
+
324
336
  def setup_master_monitor
325
337
  request_master_election
326
338
  @timers << EM::PeriodicTimer.new(20) do
@@ -350,18 +362,16 @@ module Sensu
350
362
  end
351
363
 
352
364
  def stop_reactor
353
- EM::Timer.new(1) do
354
- @logger.info('[stop] -- completing handlers in progress')
355
- complete_in_progress = EM::tick_loop do
356
- if @handlers_in_progress == 0
357
- :stop
358
- end
365
+ @logger.info('[stop] -- completing handlers in progress')
366
+ complete_in_progress = EM::tick_loop do
367
+ if @handlers_in_progress == 0
368
+ :stop
359
369
  end
360
- complete_in_progress.on_stop do
361
- @logger.warn('[stop] -- stopping reactor')
362
- EM::PeriodicTimer.new(0.25) do
363
- EM::stop_event_loop
364
- end
370
+ end
371
+ complete_in_progress.on_stop do
372
+ @logger.warn('[stop] -- stopping reactor')
373
+ EM::PeriodicTimer.new(0.25) do
374
+ EM::stop_event_loop
365
375
  end
366
376
  end
367
377
  end
@@ -371,19 +381,20 @@ module Sensu
371
381
  @timers.each do |timer|
372
382
  timer.cancel
373
383
  end
374
- @logger.warn('[stop] -- unsubscribing from keepalives')
375
- @keepalive_queue.unsubscribe do
376
- @logger.warn('[stop] -- unsubscribing from results')
377
- @result_queue.unsubscribe do
378
- if @is_master
379
- @redis.del('lock:master').callback do
380
- @logger.warn('[stop] -- resigned as master')
384
+ unless @rabbitmq.reconnecting?
385
+ @logger.warn('[stop] -- unsubscribing from keepalives')
386
+ @keepalive_queue.unsubscribe do
387
+ @logger.warn('[stop] -- unsubscribing from results')
388
+ @result_queue.unsubscribe do
389
+ resign_as_master do
381
390
  stop_reactor
382
391
  end
383
- else
384
- stop_reactor
385
392
  end
386
393
  end
394
+ else
395
+ resign_as_master do
396
+ stop_reactor
397
+ end
387
398
  end
388
399
  end
389
400
  end
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.9.4.beta.1"
2
+ VERSION = "0.9.4.beta.2"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196241
4
+ hash: 62196247
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 4
10
10
  - beta
11
- - 1
12
- version: 0.9.4.beta.1
11
+ - 2
12
+ version: 0.9.4.beta.2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Sean Porter
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-02-22 00:00:00 -08:00
21
+ date: 2012-02-23 00:00:00 -08:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -218,6 +218,7 @@ files:
218
218
  - lib/sensu/api.rb
219
219
  - lib/sensu/client.rb
220
220
  - lib/sensu/config.rb
221
+ - lib/sensu/patches/amqp.rb
221
222
  - lib/sensu/patches/redis.rb
222
223
  - lib/sensu/patches/ruby.rb
223
224
  - lib/sensu/server.rb