majordomo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/majordomo/version.rb +1 -1
- data/lib/majordomo/worker.rb +25 -13
- metadata +3 -3
data/lib/majordomo/version.rb
CHANGED
data/lib/majordomo/worker.rb
CHANGED
@@ -25,12 +25,11 @@ class Majordomo::Worker
|
|
25
25
|
|
26
26
|
# Return address, if any
|
27
27
|
@reply_to = nil
|
28
|
-
|
28
|
+
|
29
29
|
@broker = broker
|
30
30
|
@service = service
|
31
31
|
@verbose = verbose
|
32
32
|
@ctx = ZMQ::Context.new
|
33
|
-
@poller = ZMQ::Poller.new
|
34
33
|
|
35
34
|
reconnect_to_broker
|
36
35
|
end
|
@@ -55,20 +54,27 @@ class Majordomo::Worker
|
|
55
54
|
rescue => e
|
56
55
|
break # Interrupted
|
57
56
|
end
|
58
|
-
|
57
|
+
case items
|
58
|
+
when 0
|
59
|
+
# nothing waiting, but not an error
|
60
|
+
log "timed out on poll, reducing liveness"
|
61
|
+
reduce_liveness
|
62
|
+
when -1
|
63
|
+
msg = "error polling socket: errno is #{ZMQ::Util.error_string}"
|
64
|
+
log msg
|
65
|
+
raise msg
|
66
|
+
else
|
59
67
|
if (result = handle_message)
|
60
|
-
|
61
68
|
log "result from handle_message: |#{result}|"
|
62
69
|
return result
|
63
70
|
end
|
64
|
-
else
|
65
|
-
reduce_liveness
|
66
71
|
end
|
67
72
|
# Send HEARTBEAT if it's time
|
68
73
|
if Time.now > @heartbeat_at
|
69
74
|
send_to_broker(Majordomo::W_HEARTBEAT)
|
70
75
|
@heartbeat_at = Time.now + 1e-3*@heartbeat
|
71
76
|
end
|
77
|
+
|
72
78
|
end
|
73
79
|
log "W: interrupt received, killing worker…"
|
74
80
|
return nil
|
@@ -78,14 +84,18 @@ class Majordomo::Worker
|
|
78
84
|
|
79
85
|
def reconnect_to_broker
|
80
86
|
if @worker
|
81
|
-
@poller.
|
87
|
+
@poller.deregister_readable @worker
|
82
88
|
@worker.close
|
83
89
|
end
|
90
|
+
# for some reason, if we don't register a new poller,
|
91
|
+
# we get an error on the next poll. Very mysterious, and this
|
92
|
+
# solution is decidedly suboptimal. FIX
|
93
|
+
@poller = ZMQ::Poller.new
|
84
94
|
@worker = @ctx.socket(ZMQ::DEALER)
|
85
95
|
|
86
96
|
@worker.setsockopt(ZMQ::LINGER, 0)
|
87
97
|
@worker.connect @broker
|
88
|
-
@poller.
|
98
|
+
@poller.register_readable @worker
|
89
99
|
log "I: connecting to broker at #{@broker}…"
|
90
100
|
# Register service with broker
|
91
101
|
send_to_broker Majordomo::W_READY, @service, []
|
@@ -116,10 +126,11 @@ class Majordomo::Worker
|
|
116
126
|
|
117
127
|
def handle_message
|
118
128
|
msg = []
|
129
|
+
|
119
130
|
@worker.recv_strings(msg)
|
120
131
|
log "I: received message from broker: #{msg} "
|
121
132
|
|
122
|
-
@liveness =
|
133
|
+
@liveness = HEARTBEAT_LIVENESS
|
123
134
|
# Don't try to handle errors, just assert noisily
|
124
135
|
raise "expected at least 3 parts" unless msg.length >= 3
|
125
136
|
log "full message: #{msg}"
|
@@ -138,13 +149,14 @@ class Majordomo::Worker
|
|
138
149
|
# pop empty
|
139
150
|
raise "no null frame" unless empty == ''
|
140
151
|
|
141
|
-
return body # We have a request to process
|
142
|
-
when Majordomo::W_HEARTBEAT
|
152
|
+
return body # We have a request to process when Majordomo::W_HEARTBEAT
|
143
153
|
# Do nothing for heartbeats
|
144
154
|
when Majordomo::W_DISCONNECT
|
145
155
|
reconnect_to_broker
|
156
|
+
when Majordomo::W_HEARTBEAT
|
157
|
+
# pass
|
146
158
|
else
|
147
|
-
log "E: invalid input message: #{msg}"
|
159
|
+
log "E: invalid input message: #{command}: #{msg}"
|
148
160
|
end
|
149
161
|
return nil # only return message if we found one
|
150
162
|
end
|
@@ -157,7 +169,7 @@ class Majordomo::Worker
|
|
157
169
|
log "W: disconnected from broker - retrying…"
|
158
170
|
end
|
159
171
|
begin
|
160
|
-
time.sleep(
|
172
|
+
time.sleep(1*@reconnect)
|
161
173
|
rescue => e # KeyboardInterrupt:
|
162
174
|
return nil
|
163
175
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: majordomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi-rzmq
|
16
|
-
requirement: &
|
16
|
+
requirement: &13299660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13299660
|
25
25
|
description: Majordomo for Ruby
|
26
26
|
email:
|
27
27
|
- mark@ninjablocks.com
|