spacebunny 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfa2408a04f66e41361f1f5a03014f7db0fae232
4
- data.tar.gz: 7a2fc8544b0125b1f0ae33ea70a7520a961572da
3
+ metadata.gz: 7374dde1dc5ef97f68a8896120f12ee9d84d88be
4
+ data.tar.gz: 77dee2b92ec3fea47d0214925be32076f9c7637e
5
5
  SHA512:
6
- metadata.gz: b71f3cd4bffa6b2eb9b037e6388f838beb7090580036cabd18fa715914cbce9381cb4b744926ab09632a92ff21bac826c8b2289c9a6195ccb43e6a9a75d14f19
7
- data.tar.gz: 7f210d44964769111087fccc18627929b650972bc944208b18e9603e94431db142a982facdec0d771fbf5c4bc0fae07e7b2e6eab55e87fac5df643e8fb135481
6
+ metadata.gz: b7e20c7aaf099bb1f07aed48096f965487b9348f977a207670ffe3e36afdcf614640316cd1a1d343548aab2d36e63943b16b8fb063e8231314bae50235394758
7
+ data.tar.gz: e90a3c501960c2978c74a19b70f177572cf4eb3f681ab621f8ede136ed654a753244056ad791a480e8630e44a90f1efc3836c78702fa8931b827a39cea889aaa
@@ -69,18 +69,24 @@ module Spacebunny
69
69
  alias_method :inbox, :on_receive
70
70
 
71
71
  def publish(channel_name, message, options = {})
72
- check_client
73
- channel_key = if options[:with_confirm]
74
- "#{channel_name}_confirm"
75
- else
76
- channel_name
77
- end.to_sym
78
-
79
- unless @built_exchanges[channel_key]
80
- @built_exchanges[channel_key] = create_channel(channel_name, options)
72
+ if check_client
73
+ channel_key = if options[:with_confirm]
74
+ "#{channel_name}_confirm"
75
+ else
76
+ channel_name
77
+ end.to_sym
78
+
79
+ unless @built_exchanges[channel_key]
80
+ @built_exchanges[channel_key] = create_channel(channel_name, options)
81
+ end
82
+ # Call Bunny "publish"
83
+ res = @built_exchanges[channel_key].publish message, channel_options(channel_name, options)
84
+ @logger.debug 'Message published'
85
+ res
86
+ else
87
+ @logger.debug 'Message NOT published due to client not connected'
88
+ false
81
89
  end
82
- # Call Bunny publish method
83
- @built_exchanges[channel_key].publish message, channel_options(channel_name, options)
84
90
  end
85
91
 
86
92
  def wait_for_publish_confirms
@@ -114,8 +120,10 @@ module Spacebunny
114
120
  raise ClientNotConnected
115
121
  else
116
122
  @logger.error 'Client not connected! Check internet connection'
123
+ return false
117
124
  end
118
125
  end
126
+ true
119
127
  end
120
128
 
121
129
  def create_channel(name, options = {})
@@ -50,7 +50,18 @@ module Spacebunny
50
50
  private
51
51
 
52
52
  def check_client
53
- raise ClientNotConnected, 'Client not connected. Did you call client.connect?' unless client_connected?
53
+ unless client
54
+ raise ClientNotSetup
55
+ end
56
+ unless client.connected?
57
+ if raise_on_error
58
+ raise ClientNotConnected
59
+ else
60
+ @logger.error 'Client not connected! Check internet connection'
61
+ return false
62
+ end
63
+ end
64
+ true
54
65
  end
55
66
 
56
67
  def client_connected?
@@ -90,26 +101,31 @@ module Spacebunny
90
101
  to_ack, auto_ack = parse_ack options.fetch(:ack, :manual)
91
102
  from_cache = options.fetch :from_cache, false
92
103
 
93
- check_client
94
- ls_channel = client.create_channel
95
- live_stream_name = "#{live_stream_data_from_name(name)[:id]}.live_stream"
96
- if from_cache
97
- live_stream = ls_channel.queue live_stream_name, DEFAULT_QUEUE_OPTIONS
98
- else
99
- ls_exchange = ls_channel.fanout live_stream_name, DEFAULT_EXCHANGE_OPTIONS
100
- live_stream = ls_channel.queue("#{client}_#{Time.now.to_f}.live_stream.temp", auto_delete: true)
101
- .bind ls_exchange, routing_key: '#'
102
- end
104
+ if check_client
105
+ ls_channel = client.create_channel
106
+ live_stream_name = "#{live_stream_data_from_name(name)[:id]}.live_stream"
107
+ if from_cache
108
+ live_stream = ls_channel.queue live_stream_name, DEFAULT_QUEUE_OPTIONS
109
+ else
110
+ ls_exchange = ls_channel.fanout live_stream_name, DEFAULT_EXCHANGE_OPTIONS
111
+ live_stream = ls_channel.queue("#{client}_#{Time.now.to_f}.live_stream.temp", auto_delete: true)
112
+ .bind ls_exchange, routing_key: '#'
113
+ end
103
114
 
104
- live_stream.subscribe(block: blocking, manual_ack: to_ack) do |delivery_info, metadata, payload|
105
- message = LiveStream::Message.new ls_channel, options, delivery_info, metadata, payload
115
+ live_stream.subscribe(block: blocking, manual_ack: to_ack) do |delivery_info, metadata, payload|
116
+ message = LiveStream::Message.new ls_channel, options, delivery_info, metadata, payload
106
117
 
107
- yield message
118
+ yield message
108
119
 
109
- # If ack is :auto then ack current message
110
- if to_ack && auto_ack
111
- message.ack
120
+ # If ack is :auto then ack current message
121
+ if to_ack && auto_ack
122
+ message.ack
123
+ end
112
124
  end
125
+ return true
126
+ else
127
+ @logger.debug 'Not subscribed due to client not connected'
128
+ false
113
129
  end
114
130
  end
115
131
  end
@@ -1,3 +1,3 @@
1
1
  module Spacebunny
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spacebunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Verlato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-08 00:00:00.000000000 Z
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http