class Tapsoob::Operation
Attributes
database_url[R]
dump_path[R]
opts[R]
Public Class Methods
factory(type, database_url, dump_path, opts)
click to toggle source
# File lib/tapsoob/operation.rb, line 140 def self.factory(type, database_url, dump_path, opts) type = :resume if opts[:resume] klass = case type when :pull then Tapsoob::Pull when :push then Tapsoob::Push when :resume then eval(opts[:klass]) else raise "Unknown Operation Type -> #{type}" end klass.new(database_url, dump_path, opts) end
new(database_url, dump_path = nil, opts={})
click to toggle source
# File lib/tapsoob/operation.rb, line 12 def initialize(database_url, dump_path = nil, opts={}) @database_url = database_url @dump_path = dump_path @opts = opts @exiting = false end
Public Instance Methods
apply_table_filter(tables)
click to toggle source
# File lib/tapsoob/operation.rb, line 39 def apply_table_filter(tables) return tables unless table_filter || exclude_tables re = table_filter ? Regexp.new(table_filter) : nil if tables.kind_of?(Hash) ntables = {} tables.each do |t, d| if !exclude_tables.include?(t.to_s) && (!re || !re.match(t.to_s).nil?) ntables[t] = d end end ntables else tables.reject { |t| exclude_tables.include?(t.to_s) || (re && re.match(t.to_s).nil?) } end end
catch_errors(&blk)
click to toggle source
# File lib/tapsoob/operation.rb, line 132 def catch_errors(&blk) begin blk.call rescue Exception => e raise e end end
completed_tables()
click to toggle source
# File lib/tapsoob/operation.rb, line 103 def completed_tables opts[:completed_tables] ||= [] end
db()
click to toggle source
# File lib/tapsoob/operation.rb, line 115 def db @db ||= Sequel.connect(database_url) @db.loggers << Tapsoob.log if opts[:debug] # Set parameters if @db.uri =~ /oracle/i @db << "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'" @db << "ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS:FF6'" end @db end
default_chunksize()
click to toggle source
# File lib/tapsoob/operation.rb, line 99 def default_chunksize opts[:default_chunksize] end
exclude_tables()
click to toggle source
# File lib/tapsoob/operation.rb, line 35 def exclude_tables opts[:exclude_tables] || [] end
exiting?()
click to toggle source
# File lib/tapsoob/operation.rb, line 79 def exiting? !!@exiting end
file_prefix()
click to toggle source
# File lib/tapsoob/operation.rb, line 19 def file_prefix "op" end
format_number(num)
click to toggle source
# File lib/tapsoob/operation.rb, line 128 def format_number(num) num.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") end
indexes_first?()
click to toggle source
# File lib/tapsoob/operation.rb, line 27 def indexes_first? !!opts[:indexes_first] end
log()
click to toggle source
# File lib/tapsoob/operation.rb, line 56 def log Tapsoob.log.level = Logger::DEBUG if opts[:debug] Tapsoob.log end
resuming?()
click to toggle source
# File lib/tapsoob/operation.rb, line 95 def resuming? opts[:resume] == true end
setup_signal_trap()
click to toggle source
# File lib/tapsoob/operation.rb, line 83 def setup_signal_trap trap("INT") { puts "\nCompleting current action..." @exiting = true } trap("TERM") { puts "\nCompleting current action..." @exiting = true } end
skip_schema?()
click to toggle source
# File lib/tapsoob/operation.rb, line 23 def skip_schema? !!opts[:skip_schema] end
store_session()
click to toggle source
# File lib/tapsoob/operation.rb, line 61 def store_session file = "#{file_prefix}_#{Time.now.strftime("%Y%m%d%H%M")}.dat" log.info "\nSaving session to #{file}..." File.open(file, 'w') do |f| f.write(JSON.generate(to_hash)) end end
stream_state()
click to toggle source
# File lib/tapsoob/operation.rb, line 107 def stream_state opts[:stream_state] ||= {} end
stream_state=(val)
click to toggle source
# File lib/tapsoob/operation.rb, line 111 def stream_state=(val) opts[:stream_state] = val end
table_filter()
click to toggle source
# File lib/tapsoob/operation.rb, line 31 def table_filter opts[:table_filter] end
to_hash()
click to toggle source
# File lib/tapsoob/operation.rb, line 69 def to_hash { :klass => self.class.to_s, :database_url => database_url, :stream_state => stream_state, :completed_tables => completed_tables, :table_filter => table_filter, } end