kosmonaut 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1 -0
- data/lib/kosmonaut/version.rb +1 -1
- data/lib/kosmonaut/worker.rb +16 -18
- metadata +1 -1
data/ChangeLog
CHANGED
data/lib/kosmonaut/version.rb
CHANGED
data/lib/kosmonaut/worker.rb
CHANGED
@@ -6,7 +6,7 @@ module Kosmonaut
|
|
6
6
|
include Kosmonaut
|
7
7
|
|
8
8
|
RECONNECT_DELAY = 1000 # in milliseconds
|
9
|
-
HEARTBEAT_INTERVAL =
|
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 : #{
|
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
|
-
|
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)
|