Skip to content

Commit

Permalink
[api] Do not use class variables but global variables
Browse files Browse the repository at this point in the history
bunny will start a thread - and it might be good to actually start this
thread on initial startup, but this would be specific to the web server
used
  • Loading branch information
coolo committed May 27, 2017
1 parent 5736717 commit 0016b97
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/api/app/models/event/send_to_bus.rb
@@ -1,9 +1,11 @@
module Event
# performed from delayed job triggered by clockwork
class SendToBus
def self.connection(config)
@@conn ||= Bunny.new(config['url'], log_level: Logger::DEBUG)
@@conn.start
def connection(config)
return $rabbitmq_connection if $rabbitmq_connection
$rabbitmq_connection = Bunny.new(config['url'], log_level: Logger::DEBUG)
$rabbitmq_connection.start
return $rabbitmq_connection
end

def amqp_config
Expand All @@ -14,7 +16,7 @@ def bus_topic(config)
# no config, nil topic
return if config.empty? || config['url'].empty?

ch = self.class.connection(config).create_channel
ch = connection(config).create_channel
# this has to be a predefined topic
ch.topic(config.fetch('topic', 'pubsub'), persistent: true, passive: true)
end
Expand Down

0 comments on commit 0016b97

Please sign in to comment.