Class: FlareUp::Boot

Inherits:
Object
  • Object
show all
Defined in:
lib/flare_up/boot.rb

Class Method Summary collapse

Class Method Details

.boot(options) ⇒ Object

TODO: This control flow is untested



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/flare_up/boot.rb', line 6

def self.boot(options)
  conn = create_connection(options)
  copy = create_copy_command(options)

  begin
    Emitter.info("Executing command: #{copy.get_command}")
    handle_load_errors(copy.execute(conn))
  rescue CopyCommandError => e
    Emitter.error(e.message)
    CLI.bailout(1)
  end

end

.create_connection(options) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/flare_up/boot.rb', line 20

def self.create_connection(options)
  FlareUp::Connection.new(
    options[:redshift_endpoint],
    options[:database],
    options[:redshift_username],
    options[:redshift_password]
  )
end

.create_copy_command(options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flare_up/boot.rb', line 29

def self.create_copy_command(options)
  copy = FlareUp::CopyCommand.new(
    options[:table],
    options[:data_source],
    options[:aws_access_key],
    options[:aws_secret_key]
  )
  copy.columns = options[:column_list] if options[:column_list]
  copy.options = options[:copy_options] if options[:copy_options]
  copy
end

.handle_load_errors(stl_load_errors) ⇒ Object

TODO: How can we test this?



42
43
44
45
46
47
48
49
# File 'lib/flare_up/boot.rb', line 42

def self.handle_load_errors(stl_load_errors)
  return if stl_load_errors.empty?
  Emitter.error("There was an error processing the COPY command.  Displaying the last (#{stl_load_errors.length}) errors.")
  stl_load_errors.each do |e|
    Emitter.error(e.pretty_print)
  end
  CLI.bailout(1)
end