app/cyclid_ui/controllers/health.rb in cyclid-ui-0.2.0 vs app/cyclid_ui/controllers/health.rb in cyclid-ui-0.2.1

- old
+ new

@@ -10,19 +10,22 @@ # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +require 'sinatra/cross_origin' require 'sinatra-health-check' require 'memcached' # Top level module for all of the core Cyclid code. module Cyclid module UI module Controllers # Controller for all Health related API endpoints class Health < Base + register Sinatra::CrossOrigin + def initialize(_app) super @checker = SinatraHealthCheck::Checker.new(logger: Cyclid.logger, timeout: 0) @@ -33,17 +36,19 @@ # Return either 200 (healthy) or 503 (unhealthy) based on the status of # the healthchecks. This is intended to be used by things like load # balancers and active monitors. get '/health/status' do + cross_origin @checker.healthy? ? 200 : 503 end # Return verbose information on the status of the individual checks; # note that this method always returns 200 with a message body, so it is # not suitable for general health checks unless the caller intends to # parse the message body for the health status. get '/health/info' do + cross_origin @checker.status.to_json end end end