class WTOSC::Executor
Class that contains a serie of calls required for spaceship to execute the
Public Class Methods
new(queries, options = {}, before: [], after: [])
click to toggle source
# File lib/executor.rb, line 4 def initialize(queries, options = {}, before: [], after: []) raise ArgumentError if queries.empty? percona_commands = commands(queries, options) @after = after @commands = before.concat(percona_commands, after) end
Public Instance Methods
clean_up!()
click to toggle source
# File lib/executor.rb, line 20 def clean_up! warning 'Cleaning up...' execute!(@after) end
execute!(run_commands = @commands)
click to toggle source
# File lib/executor.rb, line 13 def execute!(run_commands = @commands) run_commands.each_with_index do |command, index| command.call(self) success "Finished step (#{index + 1}/#{run_commands.size})" end end
success(message)
click to toggle source
# File lib/executor.rb, line 25 def success(message) return if ENV['RACK_ENV'] == 'test' puts "\e[32m\n#{message}\e[0m" end
suppress()
click to toggle source
# File lib/executor.rb, line 37 def suppress return '' unless ENV['RACK_ENV'] == 'test' " > /dev/null" end
warning(message)
click to toggle source
# File lib/executor.rb, line 31 def warning(message) return if ENV['RACK_ENV'] == 'test' puts "\e[33m\n#{message}\n---\e[0m" end
Private Instance Methods
commands(queries, options)
click to toggle source
# File lib/executor.rb, line 45 def commands(queries, options) queries.flat_map do |query| full_query = ShellCommand.build!(query.merge(options)) [ WTOSC::PerconaCommand.new(full_query + '--dry-run'), WTOSC::PerconaConfirmer, WTOSC::PerconaCommand.new(full_query + '--execute') ] end end