-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration:check rake task that checks a configuration (#4785)
* Added configuration:check rake task that checks a configuration * CR
- Loading branch information
1 parent
ac2655c
commit d8cc171
Showing
3 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'task_helpers' | ||
|
||
namespace :configuration do | ||
desc 'Checks that the application was configured correctly' | ||
task check: :environment do | ||
required_env_vars = %w[SECRET_KEY_BASE BIGBLUEBUTTON_ENDPOINT BIGBLUEBUTTON_SECRET DATABASE_URL REDIS_URL].freeze | ||
|
||
# Initial check that variables are set | ||
info 'Checking required environment variables:' | ||
required_env_vars.each do |var| | ||
failed("#{var} not set correctly") if ENV[var].blank? | ||
end | ||
passed | ||
|
||
info 'Checking connection to Postgres Database:' | ||
begin | ||
ActiveRecord::Base.establish_connection # Establishes connection | ||
ActiveRecord::Base.connection # Calls connection object | ||
failed('Unable to connect to Database') unless ActiveRecord::Base.connected? | ||
rescue StandardError => e | ||
failed("Unable to connect to Database - #{e}") | ||
end | ||
passed | ||
|
||
info 'Checking connection to Redis Cache:' | ||
begin | ||
Redis.new.ping | ||
rescue StandardError => e | ||
failed("Unable to connect to Redis - #{e}") | ||
end | ||
passed | ||
|
||
info 'Checking connection to BigBlueButton:' | ||
test_request(Rails.configuration.bigbluebutton_endpoint) | ||
checksum = Digest::SHA1.hexdigest("getMeetings#{Rails.configuration.bigbluebutton_secret}") | ||
test_request("#{Rails.configuration.bigbluebutton_endpoint}getMeetings?checksum=#{checksum}") | ||
passed | ||
|
||
if ENV['SMTP_SERVER'].present? | ||
info 'Checking connection to SMTP Server' | ||
begin | ||
UserMailer.with(to: ENV.fetch('SMTP_SENDER_EMAIL', nil), subject: ENV.fetch('SMTP_SENDER_EMAIL', nil)).test_email.deliver_now | ||
rescue StandardError => e | ||
failed("Unable to connect to SMTP Server - #{e}") | ||
end | ||
passed | ||
end | ||
|
||
exit 0 | ||
end | ||
end | ||
|
||
# Takes the full URL including the protocol | ||
def test_request(url) | ||
uri = URI(url) | ||
res = Net::HTTP.get(uri) | ||
|
||
doc = Nokogiri::XML(res) | ||
failed("Could not get a valid response from BigBlueButton server - #{res}") if doc.css('returncode').text != 'SUCCESS' | ||
rescue StandardError => e | ||
failed("Error connecting to BigBlueButton server - #{e}") | ||
end | ||
|
||
def passed | ||
success 'Passed' | ||
end | ||
|
||
def failed(msg) | ||
err "Failed - #{msg}" | ||
end |