Class: Monitors::Neighborhood
- Inherits:
-
BaseMonitor
show all
- Defined in:
- lib/poolparty/monitors/monitors/neighborhood_monitor.rb
Instance Method Summary
collapse
Methods inherited from BaseMonitor
#after_close_callbacks, #before_close_callbacks, #initialize
Instance Method Details
#get(data = nil) ⇒ Object
10
11
12
|
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 10
def get(data=nil)
neighborhood
end
|
#post(data) ⇒ Object
27
28
29
30
31
|
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 27
def post(data)
received = JSON.parse(data)
@neighborhood = JSON.parse(data)
save
end
|
#put(data, from = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 14
def put(data, from=nil)
@neighborhood_instances = merge_array_of_hashes_with_key(neighborhood.instances, JSON.parse(data), 'ip')
@neighborhood = {@neighborhood[:instances] => @neighborhood_instances}
after_close do
if @neighborhood.instances.size>1
puts "Pinging #{"#{@neighborhood.instances.rand.ip}/neighborhood"}"
RestClient.put "#{@neighborhood.instances.rand.ip}/neighborhood", @neighborhood, :content_type => 'text/x-json'
end
end
save
end
|