lib/flare_up/boot.rb in flare-up-0.8 vs lib/flare_up/boot.rb in flare-up-0.9
- old
+ new
@@ -1,13 +1,13 @@
module FlareUp
class Boot
# TODO: This control flow is untested and too procedural
- def self.boot
+ def self.boot(command)
conn = create_connection
- copy = create_copy_command
+ cmd = create_command(command)
begin
trap('SIGINT') do
Emitter.warn("\nCTRL-C received; cancelling COPY command...")
error_message = conn.cancel_current_command
@@ -17,16 +17,16 @@
Emitter.success('COPY command cancelled.')
end
CLI.bailout(1)
end
- Emitter.info("Executing command: #{copy.get_command}")
- handle_load_errors(copy.execute(conn))
+ Emitter.info("Executing command: #{cmd.get_command}")
+ handle_load_errors(cmd.execute(conn))
rescue ConnectionError => e
Emitter.error(e.message)
CLI.bailout(1)
- rescue CopyCommandError => e
+ rescue CommandError => e
Emitter.error(e.message)
CLI.bailout(1)
end
end
@@ -39,21 +39,21 @@
OptionStore.get(:redshift_password)
)
end
private_class_method :create_connection
- def self.create_copy_command
- copy = FlareUp::CopyCommand.new(
+ def self.create_command(klass)
+ cmd = klass.new(
OptionStore.get(:table),
OptionStore.get(:data_source),
OptionStore.get(:aws_access_key),
OptionStore.get(:aws_secret_key)
)
- copy.columns = OptionStore.get(:column_list) if OptionStore.get(:column_list)
- copy.options = OptionStore.get(:copy_options) if OptionStore.get(:copy_options)
- copy
+ cmd.columns = OptionStore.get(:column_list) if OptionStore.get(:column_list)
+ cmd.options = OptionStore.get(:copy_options) if OptionStore.get(:copy_options)
+ cmd
end
- private_class_method :create_copy_command
+ private_class_method :create_command
# TODO: Backfill tests
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.")
\ No newline at end of file