Class: FlareUp::Boot

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

Class Method Summary collapse

Class Method Details

.bootObject

TODO: This control flow is untested and too procedural



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/flare_up/boot.rb', line 6

def self.boot
  conn = create_connection
  copy = create_copy_command

  begin
    trap('SIGINT') do
      Emitter.warn("\nCTRL-C received; cancelling COPY command...")
      error_message = conn.cancel_current_command
      if error_message
        Emitter.error("Error cancelling COPY: #{error_message}")
      else
        Emitter.success('COPY command cancelled.')
      end
      CLI.bailout(1)
    end

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

end