Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quietly fail init if no database is present #51

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def self.configure
end

def self.initialize!
begin
ActiveRecord::Base.connection
rescue ActiveRecord::ActiveRecordError
Rails.logger.info('No database connection; DfE Analytics not initialized')
return
end

DfE::Analytics::Fields.check!

entities_for_analytics.each do |entity|
Expand Down
8 changes: 8 additions & 0 deletions spec/dfe/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
end
end

describe 'when no database connection is available' do
it 'recovers and logs' do
allow(ActiveRecord::Base).to receive(:connection).and_raise(ActiveRecord::ConnectionNotEstablished)
allow(Rails.logger).to receive(:info).with(/No database connection/)
expect { DfE::Analytics.initialize! }.not_to raise_error
end
end

describe 'field checks on initialization' do
# field validity is computed from allowlist, blocklist and database. See
# Analytics::Fields for more details
Expand Down