kosmonaut 0.2.2 → 0.2.3

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.
data/ChangeLog CHANGED
@@ -1,6 +1,7 @@
1
1
  2012-01-20 Krzysztof Kowalik <chris@nu7hat.ch>
2
2
 
3
3
  * test/test_kosmonaut_worker.rb: shortened test time
4
+ * lib/kosmonaut/worker.rb: improved reading, small fixes and optimizations
4
5
 
5
6
  2012-01-18 Krzysztof Kowalik <chris@nu7hat.ch>
6
7
 
@@ -2,7 +2,7 @@ module Kosmonaut
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
@@ -6,7 +6,7 @@ module Kosmonaut
6
6
  include Kosmonaut
7
7
 
8
8
  RECONNECT_DELAY = 1000 # in milliseconds
9
- HEARTBEAT_INTERVAL = 2000 # in milliseconds
9
+ HEARTBEAT_INTERVAL = 1000 # in milliseconds
10
10
 
11
11
  def initialize(url)
12
12
  super(url)
@@ -31,24 +31,24 @@ module Kosmonaut
31
31
  unless @sock
32
32
  raise Errno::ECONNREFUSED
33
33
  end
34
+ msg, cmd = nil, nil
34
35
  Timeout.timeout(((@heartbeat_ivl * 2).to_f / 1000.0).to_i + 1) {
35
36
  msg = recv(@sock)
36
37
  raise Errno::ECONNRESET if @sock.eof? || msg.empty?
37
38
  log("Worker/RECV : #{msg.join("\n").inspect}")
38
39
  cmd = msg.shift
39
-
40
- case cmd
41
- when "HB"
42
- # nothing to do...
43
- when "QT"
44
- reconnect
45
- next
46
- when "TR"
47
- message_handler(msg[0])
48
- when "ER"
49
- error_handler(msg.size < 1 ? 597 : msg[0])
50
- end
51
40
  }
41
+ case cmd
42
+ when "HB"
43
+ # nothing to do...
44
+ when "QT"
45
+ reconnect
46
+ next
47
+ when "TR"
48
+ message_handler(msg[0])
49
+ when "ER"
50
+ error_handler(msg.size < 1 ? 597 : msg[0])
51
+ end
52
52
  rescue Timeout::Error, Errno::ECONNRESET, Errno::ECONNREFUSED => err
53
53
  log("Worker/RECONNECT: " + err.to_s)
54
54
  sleep(@reconnect_delay.to_f / 1000.0)
@@ -76,9 +76,9 @@ module Kosmonaut
76
76
  private
77
77
 
78
78
  def send(s, payload)
79
- packet = pack(payload)
79
+ packet = pack(payload.dup)
80
80
  @sock.write(packet)
81
- log("Worker/SENT : #{packet.inspect}")
81
+ log("Worker/SENT : #{(payload.join("\n") + "\n").inspect}")
82
82
  end
83
83
 
84
84
  def disconnect
@@ -99,9 +99,7 @@ module Kosmonaut
99
99
  def message_handler(data)
100
100
  if respond_to?(:on_message)
101
101
  payload = JSON.parse(data.to_s)
102
- event = payload.keys.first
103
- data = data[event]
104
- on_message(event, data)
102
+ on_message(*payload.first)
105
103
  end
106
104
  rescue => err
107
105
  exception_handler(err)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosmonaut
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Krzysztof Kowalik