fluke/devops-service/commands/stack.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2015-07-23 12:54:36 +03:00
require "commands/server"
require 'commands/commands_storage'
2015-07-20 18:59:26 +03:00
module StackCommands
2015-07-23 12:54:36 +03:00
include ServerCommands
extend self
2015-07-20 18:59:26 +03:00
2015-08-05 15:06:18 +03:00
def sync_bootstrap_proc
2015-07-20 18:59:26 +03:00
lambda do |out, stack, mongo|
2015-07-30 02:14:45 +03:00
# two tries each 4 seconds, then 5 tries each 10 seconds, then 5 tries each minute.
sleep_times = [4]*2 + [10]*5 + [60]*5
2015-07-20 18:59:26 +03:00
begin
out << "Syncing stack '#{stack.id}'...\n"
sleep_times.each do |sleep_time|
sleep sleep_time
2015-07-20 18:59:26 +03:00
stack.sync_details!
if stack.stack_status != 'CREATE_IN_PROGRESS'
mongo.stack_update(stack)
out << "Stack '#{stack.id}' status is now #{stack.stack_status}"
break
end
out << "Next try...\n"
2015-07-20 18:59:26 +03:00
end
rescue StandardError => e
logger.error e.message
return 5
end
end
end
2015-08-05 15:06:18 +03:00
def bootstrap_stack_servers_proc(out, stack, mongo, provider, logger)
mongo.stack_servers(stack.id).each do |server|
key = mongo.key(server.key)
two_phase_bootstrap(server, out, provider, mongo, key.path, logger)
end
end
2015-07-23 12:54:36 +03:00
CommandsStorage.add_job_lambda(
2015-08-05 15:06:18 +03:00
sync_bootstrap: sync_bootstrap_proc
2015-07-23 12:54:36 +03:00
)
2015-07-20 18:59:26 +03:00
end