Farmbot-Web-App/app/lib/abstract_service_runner.rb

20 lines
529 B
Ruby

class AbstractServiceRunner
WAIT_TIME = Rails.env.test? ? 0.01 : 5
OFFLINE_ERROR = Bunny::TCPConnectionFailedForAllHosts
CRASH_MSG = Rails.env.test? ?
"\e[32m.\e[0m" : "Something caused the broker to crash...\n"
def go!(channel)
channel.subscribe(block: true) do |info, _, payl|
self.process(info, payl.force_encoding("UTF-8"))
end
rescue OFFLINE_ERROR, StandardError => e
unless e.is_a?(OFFLINE_ERROR)
Rollbar.error(e)
print CRASH_MSG
end
sleep WAIT_TIME
retry
end
end