lib/pushyd/endpoint.rb in pushyd-0.8.2 vs lib/pushyd/endpoint.rb in pushyd-0.9.0

- old
+ new

@@ -72,20 +72,24 @@ end # Start connexion to RabbitMQ def connect_channel busconf fail PushyDaemon::EndpointConnexionContext, "invalid bus host/port" unless busconf - info "connecting to #{busconf}" + info "connecting to bus", { + broker: busconf, + recover: AMQP_RECOVERY_INTERVAL, + heartbeat: AMQP_HEARTBEAT_INTERVAL, + prefetch: AMQP_PREFETCH + } conn = Bunny.new busconf.to_s, logger: @logger, # heartbeat: :server, automatically_recover: true, network_recovery_interval: AMQP_RECOVERY_INTERVAL, heartbeat_interval: AMQP_HEARTBEAT_INTERVAL conn.start - # Create channel, prefetch only one message at a time channel = conn.create_channel channel.prefetch(AMQP_PREFETCH) rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::AuthenticationFailureError, AMQ::Protocol::EmptyResponseError => e @@ -147,9 +151,20 @@ def handle_message rule, delivery_info, metadata, payload end def identifier len rand(36**len).to_s(36) + end + + def format_bytes number, unit="", decimals = 0 + return "Ø" if number.nil? || number.to_f.zero? + + units = ["", "k", "M", "G", "T", "P" ] + index = ( Math.log(number) / Math.log(2) ).to_i / 10 + converted = number.to_f / (1024 ** index) + + truncated = converted.round(decimals) + return "#{truncated} #{units[index]}#{unit}" end private end