simplepubsub 1.1.3 → 1.1.5

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: e4193fc0ed3384cdeb8ab00f6ec6977ec28e1b70
4
- data.tar.gz: 0b0b38417f75b4179588093ca183a2d29cf414bb
3
+ metadata.gz: cfb14c303c576a5fc3ca6c8160ef526f306bc87b
4
+ data.tar.gz: 102d5dbfa5f4925c157c7f601057c81ab12e4bbb
5
5
  SHA512:
6
- metadata.gz: cb424c06c857fa76c361f3345f5c1bc4cc311291746cabab853a5e4e57d3dcc2b23b87685cd857006ec9afd6232c8f8198d6c49d6d100a1ad05155b98219e507
7
- data.tar.gz: a1709839802a3d0b8b3dba597a2b9ccf94e1b9a3ca4addb5af81a8df7a41eb38655755712ba4203fcecc7022c9b0a08ad99b594b33e83e31343f87749cf33510
6
+ metadata.gz: 58b2c22abd456d71018b03cd589db440307cde52e63a557d121dd49e700a6a1d3b1810c3f2a35af3f5fe5e6e7d3be2526f6bfd19a94e4ead06c24d166a6a855b
7
+ data.tar.gz: 4107e7cbcca9f0328b0495fe3612d646cca0b8a410297a8f1e70e0bf713e0a2d5afe136edb7522eccfeb90532ba0008d7b015bcd8f6aaa8d2bce50742ec7600e
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/simplepubsub.rb CHANGED
@@ -9,7 +9,7 @@ require 'xml-registry'
9
9
 
10
10
  module SimplePubSub
11
11
 
12
- class Server
12
+ class Broker
13
13
 
14
14
  def self.start(host: '0.0.0.0', port: 59000)
15
15
 
@@ -89,7 +89,7 @@ module SimplePubSub
89
89
 
90
90
  attr_reader :proc, :topic, :message
91
91
 
92
- def get(topic, &get_proc)
92
+ def get(topic, options={}, &get_proc)
93
93
 
94
94
  @topic = 'subscribe to topic'
95
95
  @proc, @message = get_proc, topic
@@ -104,7 +104,7 @@ module SimplePubSub
104
104
  end
105
105
  end
106
106
 
107
- def self.connect(hostname, port: '59000', &connect_blk)
107
+ def self.connect(hostname, port: '59000', retry_count: nil, &connect_blk)
108
108
 
109
109
  pubsub = PubSub.new
110
110
  connect_blk.call(pubsub)
@@ -113,6 +113,7 @@ module SimplePubSub
113
113
 
114
114
  ws.onopen do
115
115
  puts "Connected"
116
+ retry_count = 0
116
117
  end
117
118
 
118
119
  ws.onmessage do |msg, type|
@@ -124,21 +125,27 @@ module SimplePubSub
124
125
  end
125
126
 
126
127
  ws.onclose do
127
- puts "Disconnected"
128
128
 
129
- # reconnect within a minute
130
- seconds = rand(60)
131
129
 
132
- seconds.downto(1) do |i|
133
- s = "reconnecting in %s seconds" % i;
134
- print s
135
- sleep 1
136
- print "\b" * s.length
137
- end
138
- puts
130
+ if retry_count and retry_count <= 3 then
131
+ puts "Disconnected"
132
+
133
+ # reconnect within a minute
134
+ seconds = rand(60)
139
135
 
136
+ seconds.downto(1) do |i|
137
+ s = "reconnecting in %s seconds" % i;
138
+ print s
139
+ sleep 1
140
+ print "\b" * s.length
141
+ end
142
+ puts
140
143
 
141
- self.connect hostname, port: port, &connect_blk
144
+
145
+ self.connect hostname, port: port, retry_count: retry_count+1, &connect_blk
146
+ else
147
+ puts 'Unable to connect'
148
+ end
142
149
  end
143
150
 
144
151
  EventMachine.next_tick do
@@ -156,14 +163,14 @@ module SimplePubSub
156
163
  # attempt to run a websocket assuming the EventMachine is
157
164
  # already running
158
165
 
159
- ws = c.connect(params, &connect_blk)
166
+ ws = c.connect(params)
160
167
  blk.call ws, pubsub, em_already_running = true
161
168
  rescue
162
169
 
163
170
  thread = Thread.new do
164
171
  EM.run do
165
172
 
166
- ws = c.connect(params, &connect_blk)
173
+ ws = c.connect(params)
167
174
  blk.call(ws, pubsub, em_already_running = false)
168
175
  end
169
176
  end
@@ -177,7 +184,7 @@ end
177
184
  if __FILE__ == $0 then
178
185
 
179
186
  # Server example
180
- SimplePubSub::Server.new.start
187
+ SimplePubSub::Broker.start
181
188
 
182
189
  =begin
183
190
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplepubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file