Class: Oggle::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/oggle.rb

Class Method Summary collapse

Class Method Details

.create_message(server, status) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/oggle.rb', line 26

def self.create_message(server, status)
	{
				type:"update", 
				name: server[0], 
				server:{url: server[1]['url'],
				status: status
	}}
end

.poll(servers) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/oggle.rb', line 9

def self.poll(servers)
	servers.each do|server|
		http = EM::HttpRequest.new(server[1]['url']).get :redirects => 5
	    http.errback do
			EM.next_tick { settings.sockets.each{|s| s.send(create_message(server, 'error').to_json)}}
			server[1]['status'] = 'error'
	    end
		http.callback do
			status = 'error'
			status = 'ok' if http.response.to_s.include?(server[1]['check'])
			#status = rand(3)==1?'error':'ok'
			EM.next_tick { settings.sockets.each{|s| s.send(create_message(server, status).to_json)}}
			server[1]['status'] = status
		end
	end
end