require "commands/server" require 'commands/commands_storage' module StackCommands include ServerCommands extend self def sync_stack_till_not_in_progress_proc lambda do |out, stack, mongo| # two tries each 4 seconds, then 5 tries each 10 seconds, then 5 tries each minute. sleep_times = [4]*2 + [10]*5 + [60]*5 begin out << "Syncing stack '#{stack.id}'...\n" sleep_times.each do |sleep_time| sleep sleep_time 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" end rescue StandardError => e logger.error e.message return 5 end end end CommandsStorage.add_job_lambda( sync_stack_till_not_in_progress: sync_stack_till_not_in_progress_proc ) end