coney_island 0.1.7 → 0.1.8

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: fac3cad0c5d177268909fc720873ca8e1685c3ee
4
- data.tar.gz: 61aaa5581003bde4d71cef07f0b693b7c9de8a8b
3
+ metadata.gz: be119aa818eeea8fb8b2cdf52d09f6dfa4aa7808
4
+ data.tar.gz: dfb08b7173494802f841249600e8e36290b7d69a
5
5
  SHA512:
6
- metadata.gz: 7481c573ad7cb7e7233b6228a892da32628283d1b61630acb4bd23f25bed56002bc4843df36a5b5fd65e33593c7fb6701f4042cf06fb12790b33c2e8f724be20
7
- data.tar.gz: ae1d41fd141a21d44264ad7abaa8e860295baf43f2782232d82ae966d6ed8b73f6ad8669874514d0b0822bc4ade19c52f8145ae5f29df57c37fe7d4176b9307c
6
+ metadata.gz: 899e4d474e01fda4e638d17bc850232fe47fc3ffadd96d8fbc28d14867bc47c847970efa45a386e16cc2efbd6d7b140bec6af1946bffe1ca9025b2a17e9b30c9
7
+ data.tar.gz: f22f782ce6460b553f2460b754e22525344befd733f6ee9bfb8442782957baf1d699203a5687c5e117e660c23769ebc988cb77baad934618632d10c1e5b519a3
data/lib/coney_island.rb CHANGED
@@ -44,44 +44,6 @@ module ConeyIsland
44
44
  @notifier ||= "ConeyIsland::Notifiers::#{self.config[:notifier_service]}Notifier".constantize
45
45
  end
46
46
 
47
- def self.handle_connection(log)
48
- @connection ||= AMQP.connect(self.amqp_parameters)
49
- rescue AMQP::TCPConnectionFailed => e
50
- self.tcp_connection_retries ||= 0
51
- self.tcp_connection_retries += 1
52
- if self.tcp_connection_retries >= self.tcp_connection_retry_limit
53
- message = "Failed to connect to RabbitMQ #{self.tcp_connection_retry_limit} times, bailing out"
54
- log.error(message)
55
- self.poke_the_badger(e, {
56
- code_source: 'ConeyIsland.handle_connection',
57
- reason: message}
58
- )
59
- else
60
- message = "Failed to connecto to RabbitMQ Attempt ##{self.tcp_connection_retries} time(s), trying again in #{self.tcp_connection_retry_interval} seconds..."
61
- log.error(message)
62
- self.poke_the_badger(e, {
63
- code_source: 'ConeyIsland.handle_connection',
64
- reason: message})
65
- sleep(self.tcp_connection_retry_interval)
66
- retry
67
- end
68
- else
69
- @channel ||= AMQP::Channel.new(@connection)
70
- self.exchange = @channel.topic('coney_island')
71
- end
72
-
73
- def self.exchange=(amqp_exchange)
74
- @exchange ||= amqp_exchange
75
- end
76
-
77
- def self.exchange
78
- @exchange
79
- end
80
-
81
- def self.channel
82
- @channel
83
- end
84
-
85
47
  def self.config=(config_hash)
86
48
  self.amqp_parameters = config_hash.delete :amqp_connection
87
49
  if !self.single_amqp_connection?
@@ -47,37 +47,30 @@ module ConeyIsland
47
47
  end
48
48
 
49
49
  def self.amqp_parameters
50
- @amqp_parameters
51
- end
52
-
53
- def self.handle_connection
54
50
  if ConeyIsland.single_amqp_connection?
55
- Rails.logger.info("using single connection to RabbitMQ")
56
- ConeyIsland.handle_connection(Rails.logger)
57
- @exchange = ConeyIsland.exchange
51
+ ConeyIsland.amqp_parameters
58
52
  else
59
- Rails.logger.info("using independent submitter connection to RabbitMQ")
60
- self.submitter_connection
53
+ @amqp_parameters
61
54
  end
62
55
  end
63
56
 
64
- def self.submitter_connection
57
+ def self.handle_connection
65
58
  @connection ||= AMQP.connect(self.amqp_parameters)
66
59
  rescue AMQP::TCPConnectionFailed => e
67
- @tcp_connection_retries ||= 0
68
- @tcp_connection_retries += 1
69
- if @tcp_connection_retries >= 6
70
- message = "Failed to connect to RabbitMQ 6 times, bailing out"
60
+ ConeyIsland.tcp_connection_retries ||= 0
61
+ ConeyIsland.tcp_connection_retries += 1
62
+ if ConeyIsland.tcp_connection_retries >= ConeyIsland.tcp_connection_retry_limit
63
+ message = "Failed to connect to RabbitMQ #{ConeyIsland.tcp_connection_retry_limit} times, bailing out"
71
64
  Rails.logger.error(message)
72
65
  ConeyIsland.poke_the_badger(e, {
73
- code_source: 'ConeyIsland::Submitter.submitter_connection',
66
+ code_source: 'ConeyIsland::Submitter.handle_connection',
74
67
  reason: message}
75
68
  )
76
69
  else
77
- message = "Failed to connecto to RabbitMQ Attempt ##{@tcp_connection_retries} time(s), trying again in 10 seconds..."
70
+ message = "Failed to connecto to RabbitMQ Attempt ##{ConeyIsland.tcp_connection_retries} time(s), trying again in #{ConeyIsland.tcp_connection_retry_interval} seconds..."
78
71
  Rails.logger.error(message)
79
72
  ConeyIsland.poke_the_badger(e, {
80
- code_source: 'ConeyIsland::Submitter.submitter_connection',
73
+ code_source: 'ConeyIsland::Submitter.handle_connection',
81
74
  reason: message})
82
75
  sleep(10)
83
76
  retry
@@ -1,3 +1,3 @@
1
1
  module ConeyIsland
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -59,46 +59,13 @@ module ConeyIsland
59
59
  end
60
60
 
61
61
  def self.amqp_parameters
62
- @amqp_parameters
63
- end
64
-
65
- def self.handle_connection
66
62
  if ConeyIsland.single_amqp_connection?
67
- ConeyIsland.handle_connection(self.log)
68
- @exchange = ConeyIsland.exchange
69
- @channel = ConeyIsland.channel
70
- else
71
- self.worker_connection
72
- end
73
- end
74
-
75
- def self.worker_connection
76
- @connection ||= AMQP.connect(self.amqp_parameters)
77
- rescue AMQP::TCPConnectionFailed => e
78
- @tcp_connection_retries ||= 0
79
- @tcp_connection_retries += 1
80
- if @tcp_connection_retries >= 6
81
- message = "Failed to connect to RabbitMQ 6 times, bailing out"
82
- self.log.error(message)
83
- ConeyIsland.poke_the_badger(e, {
84
- code_source: 'ConeyIsland::Worker.worker_connection',
85
- reason: message}
86
- )
63
+ ConeyIsland.amqp_parameters
87
64
  else
88
- message = "Failed to connecto to RabbitMQ Attempt ##{@tcp_connection_retries} time(s), trying again in 10 seconds..."
89
- self.log.error(message)
90
- ConeyIsland.poke_the_badger(e, {
91
- code_source: 'ConeyIsland::Worker.worker_connection',
92
- reason: message})
93
- sleep(10)
94
- retry
65
+ @amqp_parameters
95
66
  end
96
- else
97
- @channel ||= AMQP::Channel.new(@connection)
98
- @exchange = @channel.topic('coney_island')
99
67
  end
100
68
 
101
-
102
69
  def self.start
103
70
  @child_count.times do
104
71
  child_pid = Process.fork
@@ -110,30 +77,54 @@ module ConeyIsland
110
77
  end
111
78
  defined?(ActiveRecord::Base) and
112
79
  ActiveRecord::Base.establish_connection
113
- EventMachine.run do
114
80
 
115
- Signal.trap('INT') do
116
- self.shutdown('INT')
117
- end
118
- Signal.trap('TERM') do
119
- self.shutdown('TERM')
120
- end
81
+ begin
82
+ EventMachine.run do
121
83
 
122
- self.handle_connection
123
-
124
- self.log.info("Connecting to AMQP broker. Running #{AMQP::VERSION}")
84
+ Signal.trap('INT') do
85
+ self.shutdown('INT')
86
+ end
87
+ Signal.trap('TERM') do
88
+ self.shutdown('TERM')
89
+ end
125
90
 
126
- #send a heartbeat every 15 seconds to avoid aggresive network configurations that close quiet connections
127
- heartbeat_exchange = self.channel.fanout('coney_island_heartbeat')
128
- EventMachine.add_periodic_timer(15) do
129
- heartbeat_exchange.publish({:instance_name => @ticket})
91
+ AMQP.connect(self.amqp_parameters) do |connection|
92
+ self.log.info("Connected to AMQP broker. Running #{AMQP::VERSION}")
93
+ @channel ||= AMQP::Channel.new(connection)
94
+ @exchange = @channel.topic('coney_island')
95
+
96
+ #send a heartbeat every 15 seconds to avoid aggresive network configurations that close quiet connections
97
+ heartbeat_exchange = self.channel.fanout('coney_island_heartbeat')
98
+ EventMachine.add_periodic_timer(15) do
99
+ heartbeat_exchange.publish({:instance_name => @ticket})
100
+ end
101
+
102
+ self.channel.prefetch @prefetch_count
103
+ @queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
104
+ @queue.bind(self.exchange, routing_key: 'carousels.' + @ticket)
105
+ @queue.subscribe(:ack => true) do |metadata,payload|
106
+ self.handle_incoming_message(metadata,payload)
107
+ end
108
+ end
130
109
  end
131
-
132
- self.channel.prefetch @prefetch_count
133
- @queue = self.channel.queue(@full_instance_name, auto_delete: false, durable: true)
134
- @queue.bind(self.exchange, routing_key: 'carousels.' + @ticket)
135
- @queue.subscribe(:ack => true) do |metadata,payload|
136
- self.handle_incoming_message(metadata,payload)
110
+ rescue AMQP::TCPConnectionFailed => e
111
+ ConeyIsland.tcp_connection_retries ||= 0
112
+ ConeyIsland.tcp_connection_retries += 1
113
+ if ConeyIsland.tcp_connection_retries >= ConeyIsland.tcp_connection_retry_limit
114
+ message = "Failed to connect to RabbitMQ #{ConeyIsland.tcp_connection_retry_limit} times, bailing out"
115
+ self.log.error(message)
116
+ ConeyIsland.poke_the_badger(e, {
117
+ code_source: 'ConeyIsland::Worker.start',
118
+ reason: message}
119
+ )
120
+ else
121
+ message = "Failed to connecto to RabbitMQ Attempt ##{ConeyIsland.tcp_connection_retries} time(s), trying again in #{ConeyIsland.tcp_connection_retry_interval} seconds..."
122
+ self.log.error(message)
123
+ ConeyIsland.poke_the_badger(e, {
124
+ code_source: 'ConeyIsland::Worker.start',
125
+ reason: message})
126
+ sleep(10)
127
+ retry
137
128
  end
138
129
  end
139
130
  end
@@ -41,7 +41,7 @@ class ConeyIslandTest < MiniTest::Test
41
41
  @fake_channel.expect :topic, nil, [String]
42
42
  AMQP::Channel.stub(:new,@fake_channel) do
43
43
  AMQP.stub(:connect, force_tcp_error) do
44
- ConeyIsland.handle_connection(Logger.new(File.open(File::NULL, "w")))
44
+ ConeyIsland::Submitter.handle_connection
45
45
  end
46
46
  end
47
47
  @fake_channel.verify
@@ -1,2 +1,10 @@
1
1
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
2
2
  ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
3
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
4
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
5
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
6
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
7
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
8
+ Failed to connecto to RabbitMQ Attempt #1 time(s), trying again in 0 seconds...
9
+ ConeyIsland::Submitter.submit! about to iterate over this many jobs: 1
10
+ 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.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-03 00:00:00.000000000 Z
12
+ date: 2014-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails