class Acheron::Exec
Public Instance Methods
run()
click to toggle source
# File lib/acheron/exec.rb, line 12 def run check reconnect x_name = config.rabbitmq.exchange exchange = @channel.fanout(x_name) queue = @channel.queue('', exclusive: true) queue.bind(exchange) queue.subscribe(block: true) do |info, prop, body| slack JSON.parse(body)['msg'] end rescue Bunny::ConnectionClosedError => e # if the connection is closed make it reconnect and try again reconnect retry end
Private Instance Methods
check()
click to toggle source
# File lib/acheron/exec.rb, line 69 def check if config.slack.token.nil? warn 'Slack token is missing.' exit 1 end end
defaults()
click to toggle source
# File lib/acheron/exec.rb, line 47 def defaults { channel: config.slack.channel, username: config.slack.username, icon_emoji: config.slack.icon_emoji } end
faraday()
click to toggle source
# File lib/acheron/exec.rb, line 55 def faraday @faraday ||= Faraday.new(url: slack_url) do |f| f.request :url_encoded f.adapter Faraday.default_adapter end end
reconnect()
click to toggle source
# File lib/acheron/exec.rb, line 31 def reconnect bunny = Bunny.new read_timeout: 10, heartbeat: 10 bunny.start @channel = bunny.create_channel end
slack(message, opts={})
click to toggle source
# File lib/acheron/exec.rb, line 37 def slack(message, opts={}) unless config.slack.channel puts message return end opts[:text] = message payload = defaults.merge(opts) faraday.post slack_url, payload: JSON.unparse(payload) end
slack_url()
click to toggle source
# File lib/acheron/exec.rb, line 62 def slack_url @slack_url ||= "https://voicerepublic.slack.com" + "/services/hooks/incoming-webhook" + "?token=" + config.slack.token end