coney_island 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coney_island.rb +8 -4
- data/lib/coney_island/version.rb +1 -1
- data/lib/coney_island/worker.rb +40 -40
- data/test/coney_island_test.rb +1 -1
- data/test/dummy/log/test.log +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e89a4a37c2ee2c54d1971832c0a2116de95c3fe7
|
4
|
+
data.tar.gz: 695f0918f28bfb72651a51c0adde9981f87e5e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa2adee2194a6270b8b2e7d9cdfe37d6aa722e23e2ab7d7872d6702902d0120b4864b277928c7c1b969b97457ea59a96aff48d64affe557a21c81038346f9ee0
|
7
|
+
data.tar.gz: 6d4e7c6446c7c3addbbc9a8b4d6f6af741a2b2d21888544da8235e2d69a46b7e473363caf87f322780b7a67f458c8eb6f20b2539ff5820d93024a597bd851027
|
data/lib/coney_island.rb
CHANGED
@@ -30,12 +30,16 @@ module ConeyIsland
|
|
30
30
|
@tcp_connection_retry_limit ||= 6
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.tcp_connection_retry_interval
|
34
|
-
|
33
|
+
def self.tcp_connection_retry_interval
|
34
|
+
self.tcp_connection_retry_seed ** self.tcp_connection_retries
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.
|
38
|
-
@
|
37
|
+
def self.tcp_connection_retry_seed=(seed)
|
38
|
+
@tcp_connection_retry_seed = seed
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.tcp_connection_retry_seed
|
42
|
+
@tcp_connection_retry_seed ||= 2
|
39
43
|
end
|
40
44
|
|
41
45
|
def self.notifier
|
data/lib/coney_island/version.rb
CHANGED
data/lib/coney_island/worker.rb
CHANGED
@@ -117,59 +117,30 @@ module ConeyIsland
|
|
117
117
|
self.log.info("Connected to AMQP broker. Running #{AMQP::VERSION}")
|
118
118
|
connection.on_error do |conn, connection_close|
|
119
119
|
self.log.error "Handling a connection-level exception."
|
120
|
+
self.log.error
|
120
121
|
self.log.error "AMQP class id : #{connection_close.class_id}"
|
121
122
|
self.log.error "AMQP method id: #{connection_close.method_id}"
|
122
123
|
self.log.error "Status code : #{connection_close.reply_code}"
|
123
124
|
self.log.error "Error message : #{connection_close.reply_text}"
|
124
|
-
ConeyIsland.poke_the_badger({error_message: "ConeyIsland #{@ticket} Worker lost RabbitMQ Connection"}, connection_error: {
|
125
|
-
amqp_class: connection_close.class_id,
|
126
|
-
amqp_method: connection_close.method_id,
|
127
|
-
status_code: connection_close.reply_code,
|
128
|
-
message: connection_close.reply_text
|
129
|
-
})
|
130
125
|
end
|
131
|
-
@channel = AMQP::Channel.new(connection)
|
132
|
-
@channel.on_error do |ch, channel_close|
|
133
|
-
self.log.error "Handling a channel-level exception."
|
134
|
-
self.log.error "AMQP class id : #{channel_close.class_id}"
|
135
|
-
self.log.error "AMQP method id: #{channel_close.method_id}"
|
136
|
-
self.log.error "Status code : #{channel_close.reply_code}"
|
137
|
-
self.log.error "Error message : #{channel_close.reply_text}"
|
138
|
-
ConeyIsland.poke_the_badger({error_message: "ConeyIsland #{@ticket} Worker lost RabbitMQ Channel"}, connection_error: {
|
139
|
-
amqp_class: channel_close.class_id,
|
140
|
-
amqp_method: channel_close.method_id,
|
141
|
-
status_code: channel_close.reply_code,
|
142
|
-
message: channel_close.reply_text
|
143
|
-
})
|
144
|
-
end
|
145
|
-
@exchange = @channel.topic('coney_island')
|
146
126
|
#Handle a lost connection to rabbitMQ
|
147
127
|
connection.on_tcp_connection_loss do |connection, settings|
|
148
128
|
# since we lost the connection, rabbitMQ will resend all jobs we didn't finish
|
149
129
|
# so drop them and restart
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
heartbeat_exchange = self.channel.fanout('coney_island_heartbeat')
|
157
|
-
EventMachine.add_periodic_timer(15) do
|
158
|
-
heartbeat_exchange.publish({:instance_name => @ticket})
|
159
|
-
self.handle_missing_children
|
130
|
+
self.log.warn("Lost rabbit connection, attempting to reconnect...")
|
131
|
+
connection.reconnect(true, 1)
|
132
|
+
self.initialize_rabbit(connection)
|
133
|
+
# unless @shutting_down
|
134
|
+
# self.abandon_and_shutdown
|
135
|
+
# end
|
160
136
|
end
|
161
137
|
|
162
|
-
self.
|
163
|
-
@queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
|
164
|
-
@queue.bind(self.exchange, routing_key: 'carousels.' + @ticket + '.#')
|
165
|
-
@queue.subscribe(:ack => true) do |metadata,payload|
|
166
|
-
self.handle_incoming_message(metadata,payload)
|
167
|
-
end
|
138
|
+
self.initialize_rabbit(connection)
|
168
139
|
end
|
169
140
|
end
|
170
|
-
rescue AMQP::TCPConnectionFailed => e
|
141
|
+
rescue AMQP::TCPConnectionFailed, AMQP::PossibleAuthenticationFailureError => e
|
171
142
|
ConeyIsland.tcp_connection_retries ||= 0
|
172
|
-
|
143
|
+
ConeyIsland.tcp_connection_retries += 1
|
173
144
|
if ConeyIsland.tcp_connection_retries >= ConeyIsland.tcp_connection_retry_limit
|
174
145
|
message = "Failed to connect to RabbitMQ #{ConeyIsland.tcp_connection_retry_limit} times, bailing out"
|
175
146
|
self.log.error(message)
|
@@ -177,15 +148,43 @@ module ConeyIsland
|
|
177
148
|
code_source: 'ConeyIsland::Worker.start',
|
178
149
|
reason: message}
|
179
150
|
)
|
151
|
+
self.abandon_and_shutdown
|
180
152
|
else
|
181
153
|
message = "Failed to connecto to RabbitMQ Attempt ##{ConeyIsland.tcp_connection_retries} time(s), trying again in #{ConeyIsland.tcp_connection_retry_interval} seconds..."
|
182
154
|
self.log.error(message)
|
183
|
-
sleep(
|
155
|
+
sleep(ConeyIsland.tcp_connection_retry_interval)
|
184
156
|
retry
|
185
157
|
end
|
186
158
|
end
|
187
159
|
end
|
188
160
|
|
161
|
+
def self.initialize_rabbit(connection)
|
162
|
+
self.log.info('initializing rabbit connection with channel and queue...')
|
163
|
+
@channel = AMQP::Channel.new(connection)
|
164
|
+
channel.on_error do |ch, channel_close|
|
165
|
+
self.log.error "Handling a channel-level exception."
|
166
|
+
self.log.error
|
167
|
+
self.log.error "AMQP class id : #{channel_close.class_id}"
|
168
|
+
self.log.error "AMQP method id: #{channel_close.method_id}"
|
169
|
+
self.log.error "Status code : #{channel_close.reply_code}"
|
170
|
+
self.log.error "Error message : #{channel_close.reply_text}"
|
171
|
+
end
|
172
|
+
@exchange = @channel.topic('coney_island')
|
173
|
+
#send a heartbeat every 15 seconds to avoid aggresive network configurations that close quiet connections
|
174
|
+
heartbeat_exchange = self.channel.fanout('coney_island_heartbeat')
|
175
|
+
EventMachine.add_periodic_timer(15) do
|
176
|
+
heartbeat_exchange.publish({:instance_name => @ticket})
|
177
|
+
self.handle_missing_children
|
178
|
+
end
|
179
|
+
|
180
|
+
self.channel.prefetch @prefetch_count
|
181
|
+
@queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
|
182
|
+
@queue.bind(self.exchange, routing_key: 'carousels.' + @ticket + '.#')
|
183
|
+
@queue.subscribe(:ack => true) do |metadata,payload|
|
184
|
+
self.handle_incoming_message(metadata,payload)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
189
188
|
def self.handle_incoming_message(metadata,payload)
|
190
189
|
args = JSON.parse(payload)
|
191
190
|
job = Job.new(metadata, args)
|
@@ -215,6 +214,7 @@ module ConeyIsland
|
|
215
214
|
def self.shutdown(signal)
|
216
215
|
@shutting_down = true
|
217
216
|
@child_pids.each do |child_pid|
|
217
|
+
self.log("killing child #{child_pid}")
|
218
218
|
Process.kill(signal, child_pid)
|
219
219
|
end
|
220
220
|
@queue.unsubscribe rescue nil
|
data/test/coney_island_test.rb
CHANGED
@@ -36,7 +36,7 @@ class ConeyIslandTest < MiniTest::Test
|
|
36
36
|
|
37
37
|
it "retries on TCP connection errors" do
|
38
38
|
ConeyIsland.stop_running_inline
|
39
|
-
ConeyIsland.
|
39
|
+
ConeyIsland.tcp_connection_retry_seed = 0
|
40
40
|
@fake_channel = MiniTest::Mock.new
|
41
41
|
@fake_channel.expect :topic, nil, [String]
|
42
42
|
@fake_channel.expect :topic, nil, [String]
|
data/test/dummy/log/test.log
CHANGED
@@ -32,3 +32,8 @@ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
|
32
32
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
33
33
|
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
34
34
|
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
35
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
36
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
37
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
38
|
+
ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
|
39
|
+
Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coney_island
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Draut
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-05-
|
13
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|