lib/pushyd/endpoint.rb in pushyd-0.3.0 vs lib/pushyd/endpoint.rb in pushyd-0.3.1
- old
+ new
@@ -1,7 +1,7 @@
require 'bunny'
-require 'securerandom'
+require "securerandom"
module PushyDaemon
class EndpointConnexionContext < StandardError; end
class EndpointConnectionError < StandardError; end
class EndpointSubscribeContext < StandardError; end
@@ -13,30 +13,28 @@
# Prepare logger (may be NIL > won't output anything)
logfile = Conf[:log]
# Create the logger
@logger = PushyLogger.new(logfile, LOG_ROTATION)
- @logger.add Logger::INFO, "starting #{self.class.name.to_s}"
+ @logger.add Logger::INFO, "starting #{self.class.name}"
# Declare we're now logging
puts "#{self.class} logging to #{logfile}"
end
protected
def error message, lines = {}
@logger.add Logger::ERROR, "#{self.class}: #{message}", lines
- #raise "ABORT #{self.class}: #{message}"
end
def info message, lines = {}
@logger.add Logger::INFO, "#{self.class}: #{message}", lines
end
def message params = {}
# Indenting
- #indent = " " * (params[:way].length)
lines = []
# Header
message = sprintf(
"%3s %-15s %s",
@@ -66,11 +64,11 @@
# @logger.log_info message, lines
end
# Start connexion to RabbitMQ
def connect_channel busconf
- raise PushyDaemon::EndpointConnexionContext, "invalid bus host/port" unless (busconf.is_a? Hash) &&
+ fail PushyDaemon::EndpointConnexionContext, "invalid bus host/port" unless (busconf.is_a? Hash) &&
busconf[:host] && busconf[:port]
info "connecting to #{busconf[:host]} port #{busconf[:port]}"
conn = Bunny.new host: (busconf[:host].to_s || "localhost").to_s,
port: busconf[:port].to_i,
@@ -81,13 +79,13 @@
# Create channel
channel = conn.create_channel
rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::AuthenticationFailureError, AMQ::Protocol::EmptyResponseError => e
- raise PushyDaemon::EndpointConnectionError, "error connecting (#{e.class})"
- rescue Exception => e
- raise PushyDaemon::EndpointConnectionError, "unknow (#{e.inspect})"
+ fail PushyDaemon::EndpointConnectionError, "error connecting (#{e.class})"
+ rescue StandardError => e
+ fail PushyDaemon::EndpointConnectionError, "unknow (#{e.inspect})"
else
return channel
end
# Declare or return the exchange for this topic
@@ -101,12 +99,12 @@
# Check information
rule_name = rule[:name].to_s
rule_topic = rule[:topic].to_s
rule_routes = rule[:routes].to_s.split(' ')
rule_queue = "#{Conf.name}-#{PROXY_SCOPE}-#{rule[:name]}"
- raise PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking topic" unless rule_topic
- raise PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking routes" if rule_routes.empty?
+ fail PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking topic" unless rule_topic
+ fail PushyDaemon::EndpointSubscribeContext, "rule [#{rule_name}] lacking routes" if rule_routes.empty?
# Create queue for this rule (remove it beforehand)
#conn.create_channel.queue_delete(rule_queue_name)
queue = @channel.queue(rule_queue, auto_delete: false, durable: true)
@@ -128,13 +126,13 @@
handle_message rule, delivery_info, metadata, payload
end
rescue Bunny::PreconditionFailed => e
- raise PushyDaemon::EndpointSubscribeError, "PreconditionFailed: [#{rule_topic}] code(#{e.channel_close.reply_code}) message(#{e.channel_close.reply_text})"
+ fail PushyDaemon::EndpointSubscribeError, "PreconditionFailed: [#{rule_topic}] code(#{e.channel_close.reply_code}) message(#{e.channel_close.reply_text})"
- rescue Exception => e
- raise PushyDaemon::EndpointSubscribeError, "unhandled (#{e.inspect})"
+ rescue StandardError => e
+ fail PushyDaemon::EndpointSubscribeError, "unhandled (#{e.inspect})"
end
def handle_message rule, delivery_info, metadata, payload
end