Module: Doorkeepr::Nerve
- Defined in:
- lib/doorkeepr/nerve.rb
Class Method Summary collapse
- .additional_paths ⇒ Object
- .application ⇒ Object
- .config ⇒ Object
- .doorkeepr ⇒ Object
- .doorkeepr_path ⇒ Object
- .host ⇒ Object
- .instance_id ⇒ Object
- .marshal ⇒ Object
- .nerve ⇒ Object
- .port ⇒ Object
- .publish ⇒ Object
- .service(uri = "/doorkeepr", path: doorkeepr_path) ⇒ Object
- .uplink_path ⇒ Object
- .uri ⇒ Object
- .zk_hosts ⇒ Object
Class Method Details
.additional_paths ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
83 84 85 86 |
# File 'lib/doorkeepr/nerve.rb', line 83 def application @application = Doorkeepr.config.url @application ||= "rails.dev" end |
.config ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/doorkeepr/nerve.rb', line 15 def doorkeepr @doorkeepr end |
.doorkeepr_path ⇒ Object
59 60 61 62 |
# File 'lib/doorkeepr/nerve.rb', line 59 def doorkeepr_path @doorkeepr_path = Doorkeepr.config.path @doorkeepr_path ||= "/doorkeepr/publish" end |
.host ⇒ Object
63 64 65 66 |
# File 'lib/doorkeepr/nerve.rb', line 63 def host @host = Doorkeepr.config.host @host ||= "localhost" end |
.instance_id ⇒ Object
75 76 77 |
# File 'lib/doorkeepr/nerve.rb', line 75 def instance_id @instance_id ||= SecureRandom.hex(8) end |
.marshal ⇒ Object
20 21 22 23 24 |
# File 'lib/doorkeepr/nerve.rb', line 20 def marshal puts 'Doorkeepr: publish!' @threads ||= [] @threads << Thread.new { doorkeepr.run } end |
.nerve ⇒ Object
18 19 |
# File 'lib/doorkeepr/nerve.rb', line 18 def nerve end |
.port ⇒ Object
67 68 69 70 |
# File 'lib/doorkeepr/nerve.rb', line 67 def port @port = Doorkeepr.config.port @port ||= 3000 end |
.publish ⇒ Object
6 7 8 9 10 11 12 13 14 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
55 56 57 58 |
# 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 ⇒ Object
71 72 73 74 |
# File 'lib/doorkeepr/nerve.rb', line 71 def uri @uri = "/#{::OkComputer.mount_at}" if defined? ::OkComputer @uri ||= "/" end |
.zk_hosts ⇒ Object
78 79 80 81 82 |
# 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 |