Class: Flydata::Command::Sync
- Includes:
- Helpers
- Defined in:
- lib/flydata/command/sync.rb
Constant Summary collapse
- CREATE_TABLE_OPTION =
!!(ENV['FLYDATA_CREATE_TABLE_OPTION']) || false
- INSERT_PROGRESS_INTERVAL =
1000- STATUS_PARSING =
for dump.pos file
'PARSING'- STATUS_COMPLETE =
'COMPLETE'
Instance Method Summary collapse
- #check ⇒ Object
- #complete ⇒ Object
- #generate_table_ddl ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
-
#skip ⇒ Object
skip initial sync.
Methods included from Helpers
development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, format_menu_list, parse_command, print_usage, retry_on, to_command_class
Methods inherited from Base
#ask_input_table_name, #ask_yes_no, #choose_one, #flydata, #initialize, #newline, #register_crontab, #retrieve_data_entries, #separator
Constructor Details
This class inherits a constructor from Flydata::Command::Base
Instance Method Details
#check ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flydata/command/sync.rb', line 37 def check de = retrieve_data_entries.first retry_on(RestClient::Exception) do ret = do_check(de) if ret['complete'] puts "No buffer data on FlyData. #{ret.inspect}" true else puts "Now processing data on FlyData. #{ret.inspect}" false end end end |
#complete ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/flydata/command/sync.rb', line 51 def complete de = retrieve_data_entries.first sync_fm = Flydata::FileUtil::SyncFileManager.new(de) info = sync_fm.load_dump_pos if info[:status] == STATUS_COMPLETE sync_fm.save_binlog(info[:binlog_pos]) Flydata::Command::Sender.new.start else raise "Initial sync status is not complete. Try running 'flydata sync'." end end |
#generate_table_ddl ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/flydata/command/sync.rb', line 74 def generate_table_ddl de = retrieve_data_entries.first raise "There are no data entry." unless de case de['type'] when 'RedshiftMysqlDataEntry' do_generate_table_ddl(de) else raise "No supported data entry. Only mysql-redshift sync is supported." end end |
#reset ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/flydata/command/sync.rb', line 29 def reset de = retrieve_data_entries.first sync_fm = Flydata::FileUtil::SyncFileManager.new(de) [sync_fm.dump_file_path, sync_fm.dump_pos_path, sync_fm.binlog_path, sync_fm.mysql_table_marshal_dump_path, sync_fm.table_position_file_paths].flatten.each do |path| FileUtils.rm(path) if File.exists?(path) end end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flydata/command/sync.rb', line 18 def run de = retrieve_data_entries.first raise "There are no data entry." unless de case de['type'] when 'RedshiftMysqlDataEntry' sync_mysql_to_redshift(de) else raise "No supported data entry. Only mysql-redshift sync is supported." end end |
#skip ⇒ Object
skip initial sync
64 65 66 67 68 69 70 71 72 |
# File 'lib/flydata/command/sync.rb', line 64 def skip de = retrieve_data_entries.first sync_fm = Flydata::FileUtil::SyncFileManager.new(de) binlog_path = sync_fm.binlog_path `touch #{binlog_path}` puts "Created an empty binlog position file." puts "-> #{binlog_path}" puts "Run 'flydata start' to start continuous sync." end |