refactore persister
This commit is contained in:
parent
a365138164
commit
80a0c8f436
@ -14,16 +14,17 @@ class StackServersPersister
|
|||||||
|
|
||||||
# returns: { priority_as_integer => [Servers] }
|
# returns: { priority_as_integer => [Servers] }
|
||||||
def persist
|
def persist
|
||||||
puts_and_flush 'Start syncing stack servers with CID'
|
puts_and_flush 'Start saving stack servers into CID database.'
|
||||||
|
|
||||||
stack_servers_with_priority = {}
|
stack_servers_with_priority = {}
|
||||||
stack_servers_info.each do |priority, info_array|
|
|
||||||
stack_servers_with_priority[priority] = info_array.map do |info_hash|
|
@provider.stack_servers(stack).each do |provider_info|
|
||||||
out.puts "Instance '#{info_hash["id"]}' has been launched with stack."
|
server = persist_stack_server(provider_info)
|
||||||
persist_stack_server(info_hash)
|
priority = provider_info['tags']['cid:priority'].to_i
|
||||||
|
stack_servers_with_priority[priority] ||= []
|
||||||
|
stack_servers_with_priority[priority] << server
|
||||||
end
|
end
|
||||||
end
|
|
||||||
puts_and_flush "Stack servers have been synced with CID"
|
puts_and_flush "Stack servers have been saved."
|
||||||
stack_servers_with_priority.each do |priority, servers|
|
stack_servers_with_priority.each do |priority, servers|
|
||||||
out.puts "Servers with priority '#{priority}': #{servers.map(&:id).join(", ")}"
|
out.puts "Servers with priority '#{priority}': #{servers.map(&:id).join(", ")}"
|
||||||
end
|
end
|
||||||
@ -33,15 +34,6 @@ class StackServersPersister
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# returns: {priority_as_integer => array_of_sersvers_info}
|
|
||||||
def stack_servers_info
|
|
||||||
stack_servers = @provider.stack_servers(stack)
|
|
||||||
stack_servers.each do |info|
|
|
||||||
info['tags']['cid:priority'] = info['tags']['cid:priority'].to_i
|
|
||||||
end
|
|
||||||
stack_servers.group_by{|info| info['tags']['cid:priority']}
|
|
||||||
end
|
|
||||||
|
|
||||||
# takes a hash, returns Server model
|
# takes a hash, returns Server model
|
||||||
def persist_stack_server(server_info)
|
def persist_stack_server(server_info)
|
||||||
server_attrs = {
|
server_attrs = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user