waffle 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/waffle/base.rb CHANGED
@@ -6,11 +6,7 @@ module Waffle
6
6
  end
7
7
 
8
8
  def publish(flow = 'events', message = '')
9
- begin
10
- @transport.publish flow, message
11
- rescue
12
- nil
13
- end
9
+ @transport.publish flow, message
14
10
  end
15
11
 
16
12
  def subscribe(flow = '', &block)
@@ -1,14 +1,19 @@
1
+ require 'date'
1
2
  require 'bunny'
2
3
 
3
4
  module Waffle
4
5
  module Transports
5
6
  class Rabbitmq
6
7
 
8
+ CONNECTION_ATTEMPT_TIMEOUT = 30
9
+
7
10
  EXCHANGE = 'events'
8
11
 
12
+ @@last_connection_attempt = Time.now
13
+
9
14
  def initialize
10
15
  @bunny = Bunny.new Waffle::Config.url
11
- @bunny.start
16
+ connect
12
17
  end
13
18
 
14
19
  def encoder
@@ -16,13 +21,20 @@ module Waffle
16
21
  end
17
22
 
18
23
  def publish(flow = 'events', message = '')
19
- @exchange = @bunny.exchange EXCHANGE
20
- @exchange.publish message, :key => flow
24
+ begin
25
+ @exchange = @bunny.exchange EXCHANGE
26
+ @exchange.publish message, :key => flow
27
+ rescue
28
+ if (Time.now - @@last_connection_attempt) > CONNECTION_ATTEMPT_TIMEOUT
29
+ connect
30
+ end
31
+ end
21
32
  end
22
33
 
23
34
  def subscribe(flow = 'events')
24
35
  @exchange = @bunny.exchange EXCHANGE
25
36
  @queue = @bunny.queue '', :durable => true, :auto_delete => true
37
+
26
38
  if flow.is_a? Array
27
39
  flow.each{ |f| @queue.bind @exchange, :key => f }
28
40
  else
@@ -34,6 +46,17 @@ module Waffle
34
46
  end
35
47
  end
36
48
 
49
+ private
50
+
51
+ def connect
52
+ begin
53
+ @@last_connection_attempt = Time.now
54
+ @bunny.start
55
+ rescue
56
+ nil
57
+ end
58
+ end
59
+
37
60
  end
38
61
  end
39
62
  end
@@ -1,5 +1,5 @@
1
1
  module Waffle
2
2
 
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waffle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-03 00:00:00.000000000Z
12
+ date: 2012-04-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny
16
- requirement: &75204430 !ruby/object:Gem::Requirement
16
+ requirement: &76785160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75204430
24
+ version_requirements: *76785160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &75203820 !ruby/object:Gem::Requirement
27
+ requirement: &76783560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *75203820
35
+ version_requirements: *76783560
36
36
  description: Client part of Patty statistics server
37
37
  email: alexander.lomakin@gmail.com
38
38
  executables: []