module Doorkeepr::Nerve
Public Class Methods
additional_paths()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 36 def additional_paths paths = Doorkeepr.paths paths ||= [] paths.collect do |path| [ Digest::MD5.hexdigest(path), service(uri,path:path) ] end.to_h end
application()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 83 def application @application = Doorkeepr.config.url @application ||= "rails.dev" end
config()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 46 def config { instance_id: instance_id, services: { application => service, "uplink" => service(uri,path:uplink_path) }.merge(additional_paths) }.with_indifferent_access end
doorkeepr()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 15 def doorkeepr @doorkeepr end
doorkeepr_path()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 59 def doorkeepr_path @doorkeepr_path = Doorkeepr.config.path @doorkeepr_path ||= "/doorkeepr/publish" end
host()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 63 def host @host = Doorkeepr.config.host @host ||= "localhost" end
instance_id()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 75 def instance_id @instance_id ||= SecureRandom.hex(8) end
marshal()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 20 def marshal puts 'Doorkeepr: publish!' @threads ||= [] @threads << Thread.new { doorkeepr.run } end
nerve()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 18 def nerve end
port()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 67 def port @port = Doorkeepr.config.port @port ||= 3000 end
publish()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 6 def publish puts "Publishing Server with #{Doorkeepr.config.inspect}" ap config @doorkeepr = ::Nerve::Nerve.new config marshal at_exit do @threads.each{|t|t.kill} end end
service(uri="/doorkeepr",path:doorkeepr_path)
click to toggle source
# File lib/doorkeepr/nerve.rb, line 25 def service uri="/doorkeepr",path:doorkeepr_path { host: host, port: port, reporter_type: "zookeeper", zk_hosts: zk_hosts, zk_path: path, check_interval: 5, checks: [{timeout:0.2,rise:2,fall:3,type:"http",uri:uri}] } end
uplink_path()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 55 def uplink_path @uplink_path = Doorkeepr.config.uplink @uplink_path ||= "/nerve/#{Doorkeepr.config.customer}/#{Doorkeepr.config.application}/#{Doorkeepr.config.service}/services" end
uri()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 71 def uri @uri = "/#{::OkComputer.mount_at}" if defined? ::OkComputer @uri ||= "/" end
zk_hosts()
click to toggle source
# File lib/doorkeepr/nerve.rb, line 78 def zk_hosts return [ Boutons.zookeeper.s("%i:%p") ] if defined? Boutons and Boutons.respond_to? :zookeeper return Resolv::Consul.services(:zookeeper).map{|srv| "#{srv.address}:#{srv.port}" } if defined? Resolv::Consul [ "localhost:2181" ] end