Navigation Menu

Skip to content

Commit

Permalink
Use case-when
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 27, 2014
1 parent 3227481 commit f6a16ef
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions lib/droonga/command/serf_event_handler.rb
Expand Up @@ -70,11 +70,10 @@ def event_for_me?
end

def process_event
if @event_sub_name == "change_role"
case @event_sub_name
when "change_role"
save_status(:role, @payload["role"])
end

if @event_sub_name == "join"
when "join"
process_node_join
end
end
Expand All @@ -88,13 +87,34 @@ def process_node_join

return unless @payload["type"] == "replica"

current_catalog = JSON.parse(Path.catalog.read)
current_params = CatalogGenerator.catalog_to_params(current_catalog)
modifications = {
dataset => {
:add_replica_hosts => [host],
},
}
modify_catalog(modifications)
end

def process_node_unjoin
dataset = @payload["dataset"]
return unless dataset

host = @payload["host"]
return unless host

return unless @payload["type"] == "replica"

modifications = {
dataset => {
:remove_replica_hosts => [host],
},
}
modify_catalog(modifications)
end

def modify_catalog(modifications)
current_catalog = JSON.parse(Path.catalog.read)
current_params = CatalogGenerator.catalog_to_params(current_catalog)
updated_params = CatalogGenerator.update_params(current_params,
modifications)
updated_catalog = CatalogGenerator.generate(updated_params)
Expand Down

0 comments on commit f6a16ef

Please sign in to comment.