Add ping/pong health check
This commit is contained in:
22
app/controllers/ping_controller.rb
Normal file
22
app/controllers/ping_controller.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PingController < ApplicationController
|
||||||
|
before_action :postgres_connected!
|
||||||
|
after_action :verify_authorized, except: %i[index]
|
||||||
|
|
||||||
|
def index
|
||||||
|
render json: {
|
||||||
|
message: 'Pong',
|
||||||
|
timenow_in_time_zone____: DateTime.now.in_time_zone.to_i,
|
||||||
|
timenow_without_timezone: DateTime.now.to_i,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def postgres_connected!
|
||||||
|
ApplicationRecord.establish_connection
|
||||||
|
ApplicationRecord.connection
|
||||||
|
ApplicationRecord.connected?
|
||||||
|
end
|
||||||
|
end
|
@ -159,6 +159,8 @@ Rails.application.routes.draw do
|
|||||||
post '/evaluate', to: 'remote_evaluation#evaluate', via: [:post]
|
post '/evaluate', to: 'remote_evaluation#evaluate', via: [:post]
|
||||||
post '/submit', to: 'remote_evaluation#submit', via: [:post]
|
post '/submit', to: 'remote_evaluation#submit', via: [:post]
|
||||||
|
|
||||||
|
resources :ping, only: :index, defaults: {format: :json}
|
||||||
|
|
||||||
mount ActionCable.server => '/cable'
|
mount ActionCable.server => '/cable'
|
||||||
mount RailsAdmin::Engine => '/rails_admin', as: 'rails_admin'
|
mount RailsAdmin::Engine => '/rails_admin', as: 'rails_admin'
|
||||||
end
|
end
|
||||||
|
13
spec/controllers/ping_controller_spec.rb
Normal file
13
spec/controllers/ping_controller_spec.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe PingController, type: :controller do
|
||||||
|
describe 'index' do
|
||||||
|
it 'returns the wanted page and answer with HTTP Status 200' do
|
||||||
|
get :index
|
||||||
|
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
9
spec/routing/ping_routing_spec.rb
Normal file
9
spec/routing/ping_routing_spec.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe PingController, type: :routing do
|
||||||
|
context 'with routes to #show' do
|
||||||
|
it { expect(get: '/ping').to route_to('ping#index', format: :json) }
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user