Commit 6eedef64 authored by Thong Kuah's avatar Thong Kuah

Move global method to Feature class

It is surprising that this method, feature_flags_available is available
globally. Also it is surprising that this method is available only if
Gitlab.com? or in development. So we fix this by moving the method
definition to be a class method in Feature
parent 177bce50
...@@ -2,17 +2,8 @@ ...@@ -2,17 +2,8 @@
return unless Gitlab.com? || Gitlab.dev_or_test_env? return unless Gitlab.com? || Gitlab.dev_or_test_env?
def feature_flags_available?
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
active_db_connection = ActiveRecord::Base.connection.active? rescue false
active_db_connection && Feature::FlipperFeature.table_exists?
rescue ActiveRecord::NoDatabaseError
false
end
Gitlab::Application.configure do Gitlab::Application.configure do
if feature_flags_available? && ::Feature.enabled?(:active_record_transactions_tracking, type: :ops, default_enabled: :yaml) if Feature.feature_flags_available? && ::Feature.enabled?(:active_record_transactions_tracking, type: :ops, default_enabled: :yaml)
Gitlab::Database::Transaction::Observer.register! Gitlab::Database::Transaction::Observer.register!
end end
end end
...@@ -29,6 +29,15 @@ class Feature ...@@ -29,6 +29,15 @@ class Feature
class << self class << self
delegate :group, to: :flipper delegate :group, to: :flipper
def feature_flags_available?
# When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised
active_db_connection = ActiveRecord::Base.connection.active? rescue false
active_db_connection && Feature::FlipperFeature.table_exists?
rescue ActiveRecord::NoDatabaseError
false
end
def all def all
flipper.features.to_a flipper.features.to_a
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment