Project

General

Profile

« Previous | Next » 

Revision b752d4f7

Added by Lukas Zapletal over 13 years ago

  • ID b752d4f75fcc815ed89a4a3e4217ac44bb2238d3

Fixes #691 - Implement simple status service

Signed-off-by: Lukas Zapletal <>

View differences:

app/controllers/home_controller.rb
class HomeController < ApplicationController
skip_before_filter :require_login, :only => [:status]
skip_before_filter :authorize, :only => [:status]
def settings
end
def status
respond_to do |format|
format.html { redirect_to root_path and return }
format.json do
# make fake db call, measure duration and report errors
result = exception_watch { User.first }
render :json => result, :status => result[:status]
end
end
end
private
# check for exception - set the result code and duration time
def exception_watch &block
start = Time.now
result = {}
yield
result[:result] = 'ok'
result[:status] = 200
result[:db_duration_ms] = ((Time.now - start) * 1000).round.to_s
rescue Exception => e
result[:result] = 'fail'
result[:status] = 500
result[:message] = e.message
ensure
return result
end
end
config/routes.rb
map.resources :subnets, :except => [:show]
map.resources :hypervisors, :except => [:show]
map.connect 'unattended/template/:id/:hostgroup', :controller => "unattended", :action => "template"
map.connect '/status', :controller => "home", :action => "status"
#default
map.connect ':controller/:action/:id'
test/functional/home_controller_test.rb
require 'test_helper'
class HomeControllerTest < ActionController::TestCase
test "should get status without an error" do
get :status, {:format => "json"}
assert_response :success
end
end

Also available in: Unified diff