Class: RskSnitch::Nodes
- Inherits:
-
Object
- Object
- RskSnitch::Nodes
- Defined in:
- lib/rsk_snitch.rb
Overview
Checks the RSK public stats websocket to see if bitex is there
Class Method Summary collapse
- .debug=(debug) ⇒ Object
- .find(node, max_messages = 500) ⇒ Object
- .up?(node, retries = 10, wait = 10) ⇒ Boolean
- .url ⇒ Object
Class Method Details
.debug=(debug) ⇒ Object
11 12 13 |
# File 'lib/rsk_snitch.rb', line 11 def self.debug=(debug) @debug = debug end |
.find(node, max_messages = 500) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rsk_snitch.rb', line 15 def self.find(node, = 500) found = nil EM.run do ws = Faye::WebSocket::Client.new(url) = 0 ws.on :message do |event| puts event.data if @debug += 1 found = true if /"id":".*?#{node}.*?"/ =~ event.data ws.close if found || > end ws.on(:close) do found ||= false EM.stop_event_loop end end found end |
.up?(node, retries = 10, wait = 10) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/rsk_snitch.rb', line 37 def self.up?(node, retries = 10, wait = 10) retries.times do return true if find(node) sleep wait end false end |
.url ⇒ Object
7 8 9 |
# File 'lib/rsk_snitch.rb', line 7 def self.url "ws://stats.rsk.co/primus/?_primuscb=#{(Time.now.to_f * 1000).round}-0" end |