Extract valid connection types into a constant.

This commit is contained in:
Guo Xiang Tan 2016-04-07 15:45:42 +08:00
parent 48e118a054
commit 60c21a3393
2 changed files with 7 additions and 3 deletions

View file

@ -7,6 +7,7 @@ class DiscourseRedis
include Singleton
MASTER_LINK_STATUS = "master_link_status:up".freeze
CONNECTION_TYPES = %w{normal pubsub}.each(&:freeze)
def initialize
@master = true
@ -31,8 +32,11 @@ class DiscourseRedis
if slave_client.call([:info]).split("\r\n").include?(MASTER_LINK_STATUS)
logger.warn "#{log_prefix}: Master server is active, killing all connections to slave..."
slave_client.call([:client, [:kill, 'type', 'normal']])
slave_client.call([:client, [:kill, 'type', 'pubsub']])
CONNECTION_TYPES.each do |connection_type|
slave_client.call([:client, [:kill, 'type', connection_type]])
end
Discourse.clear_readonly!
Discourse.request_refresh!
@master = true

View file

@ -84,7 +84,7 @@ describe DiscourseRedis do
fallback_handler.master = false
Redis::Client.any_instance.expects(:call).with([:info]).returns(DiscourseRedis::FallbackHandler::MASTER_LINK_STATUS)
%w{normal pubsub}.each do |connection_type|
DiscourseRedis::FallbackHandler::CONNECTION_TYPES.each do |connection_type|
Redis::Client.any_instance.expects(:call).with([:client, [:kill, 'type', connection_type]])
end