Commit 9823cc80 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'hot-reload-feature-flags' into 'master'

Support hot-reloading of feature flags

See merge request gitlab-org/gitlab!40854
parents 15f8fdad e3444163
......@@ -3,3 +3,4 @@
Feature.register_feature_groups
Feature.register_definitions
Feature.register_hot_reloader unless Rails.configuration.cache_classes
......@@ -137,6 +137,12 @@ class Feature
Feature::Definition.load_all!
end
def register_hot_reloader
return unless check_feature_flags_definition?
Feature::Definition.register_hot_reloader!
end
private
def flipper
......
......@@ -107,6 +107,20 @@ class Feature
end
end
def register_hot_reloader!
# Reload feature flags on change of this file or any `.yml`
file_watcher = Rails.configuration.file_watcher.new(reload_files, reload_directories) do
# We use `Feature::Definition` as on Ruby code-reload
# a new class definition is created
Feature::Definition.load_all!
end
Rails.application.reloaders << file_watcher
Rails.application.reloader.to_run { file_watcher.execute_if_updated }
file_watcher
end
private
def load_from_file(path)
......@@ -130,6 +144,19 @@ class Feature
definitions[definition.key] = definition
end
end
def reload_files
[File.expand_path(__FILE__)]
end
def reload_directories
paths.each_with_object({}) do |path, result|
path = File.dirname(path)
Dir.glob(path).each do |matching_dir|
result[matching_dir] = 'yml'
end
end
end
end
end
end
......
......@@ -53,7 +53,10 @@ FactoryBot.define do
factory :image_diff_position do
position_type { 'image' }
x { 1 }
y { 1 }
# Fix:
# NoMethodError: undefined method `end_line=' for nil:NilClass
# from /usr/lib/ruby/2.6.0/psych/tree_builder.rb:133:in `set_end_location'
add_attribute(:y) { 1 }
width { 10 }
height { 10 }
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