Files
codeocean/app/controllers/ping_controller.rb
Sebastian Serth bc5baed05e Use exec_query for custom SQL execution
Also align how we use query Postgres from controllers.

The change is mainly due to regular (but not reproducible) issues with the `intervalstyle` defaulting to `postgres` (instead of `iso8601`) and thereby causing issues. We're just experimenting to see whether this change resolves the issue.
2022-12-06 22:41:00 +01:00

24 lines
603 B
Ruby

# 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!
# any unhandled exception leads to a HTTP 500 response.
return if ApplicationRecord.connection.exec_query('SELECT 1 as result').first['result'] == 1
raise ActiveRecord::ConnectionNotEstablished
end
end