-
Notifications
You must be signed in to change notification settings - Fork 0
/
rb-status.rb
30 lines (28 loc) · 964 Bytes
/
rb-status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'sequel'
class RbStatus < Sinatra::Base
DB = ::Sequel.connect(DB_URL)
get '/status' do
begin
response['Access-Control-Allow-Origin'] = ORIGIN_ALLOWED if defined? ORIGIN_ALLOWED
NODE_ID = 0 unless defined? NODE_ID
RETRY = 10 unless defined? RETRY
counter = after = 0
status = DB[:status]
status.filter(:node => NODE_ID).delete
status.insert(:data => Time.now, :node => NODE_ID)
after = status.filter(:node => NODE_ID).all.count
while counter <= RETRY && after <= 0
counter += 1
sleep SLEEP_TIME if defined? SLEEP_TIME
after = status.filter(:node => NODE_ID).all.count.to_s
end
if after > 0
"#{VHOST_NAME} OK with #{counter} retry and #{after} records"
else
"#{VHOST_NAME} KO with #{counter} retry and #{after} records"
end
rescue Exception => e
"#{VHOST_NAME} KO #{e.message} #{e.backtrace.inspect}"
end
end
end