class Tetrahedron::Service
Constants
- AlreadyConfigured
- Misconfigured
- Unconfigured
- Unreachable
Public Class Methods
configure(&configurator)
click to toggle source
# File lib/tetrahedron/service.rb, line 24 def self.configure(&configurator) raise AlreadyConfigured if self.configured? provider = configurator.call() raise Misconfigured unless provider.is_a? Provider self.class_variable_set(:@@provider, provider) end
configured!()
click to toggle source
# File lib/tetrahedron/service.rb, line 20 def self.configured! raise Unconfigured unless self.configured? end
configured?()
click to toggle source
# File lib/tetrahedron/service.rb, line 16 def self.configured? self.class_variable_defined?(:@@provider) end
install(application)
click to toggle source
# File lib/tetrahedron/service.rb, line 3 def self.install(application) service = Class.new(self) service.class_variable_set(:@@application, application) application.const_set(self.to_s.split('::').last, service) end
wait_until_reachable(opts={})
click to toggle source
# File lib/tetrahedron/service.rb, line 36 def self.wait_until_reachable(opts={}) Timeout::timeout(opts.fetch(:timeout, 15)) do while true begin case opts[:protocol] when :tcp TCPSocket.new(opts[:host], opts[:port]).close return true when :udp raise "This makes no sense!" end rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError # We're all good citizens, right? Kernel.sleep(1) end end end rescue Timeout::Error false end
wait_until_reachable!(opts={})
click to toggle source
# File lib/tetrahedron/service.rb, line 57 def self.wait_until_reachable!(opts={}) unless self.wait_until_reachable(opts) $stderr.puts "Unable to reach #{opts[:host]}:#{opts[:port]}!" raise Unreachable end end