class Myreplicator::ExportMetadata

Attributes

database[RW]
ensure_callbacks[R]
error[RW]
export_finished_at[RW]
export_id[RW]
export_time[RW]
export_to[RW]
export_type[RW]
failure_callbacks[R]
filepath[RW]
ignore_callbacks[R]
incremental_col[RW]
incremental_val[RW]
on_duplicate[RW]
ssh[RW]
state[RW]
store_in[RW]
success_callbacks[R]
table[RW]
zipped[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/exporter/export_metadata.rb, line 27
def initialize *args
  options = args.extract_options!
  if options[:metadata_path] 
    load options[:metadata_path] 
  else
    set_attributes options
  end
end
record(*args) { |metadata| ... } click to toggle source

Keeps track of the state of the export Stores itself in a JSON file on exit

# File lib/exporter/export_metadata.rb, line 71
def self.record *args
  options = args.extract_options!
  options.reverse_merge!(:export_time => Time.now,
                         :state => "exporting")
  begin
    metadata = ExportMetadata.new 
    metadata.set_attributes options

    yield metadata

    metadata.run_success_callbacks

  rescue Exceptions::ExportError => e
    metadata.state = "failed"     
    metadata.error =  "#{e.message}\n#{e.backtrace}"
    metadata.run_failure_callbacks

  rescue Exceptions::ExportIgnored => e
    metadata.state = "ignored"
    metadata.run_ignore_callbacks
    metadata.filepath = metadata.filepath + ".ignored"

  ensure
    metadata.export_finished_at = Time.now
    metadata.state = "failed" if metadata.state == "exporting"
    metadata.store!
    metadata.ssh.close

    metadata.run_ensure_callbacks
  end
end

Public Instance Methods

destination_filepath(tmp_dir) click to toggle source
# File lib/exporter/export_metadata.rb, line 52
def destination_filepath tmp_dir
  File.join(tmp_dir, filename)
end
equals(object) click to toggle source

Compares the object with another metadata object Return true if they are for the same table

# File lib/exporter/export_metadata.rb, line 60
def equals object
  if table == object.table && database == object.database
    return true
  end
  return false
end
filename() click to toggle source
# File lib/exporter/export_metadata.rb, line 36
def filename
  name = filepath.split("/").last
  name = zipped ? "#{name}.gz" : name
  return name     
end
metadata_filename() click to toggle source
# File lib/exporter/export_metadata.rb, line 42
def metadata_filename
  name = filepath.split("/").last
  name += ".json"
  return name
end
metadata_filepath(tmp_dir) click to toggle source
# File lib/exporter/export_metadata.rb, line 48
def metadata_filepath tmp_dir
  File.join(tmp_dir, metadata_filename)
end
on_failure(*args, &block) click to toggle source

Add a callback to run on failure of the export

# File lib/exporter/export_metadata.rb, line 105
def on_failure *args, &block
  if block_given?
    @failure_callbacks << block
  else
    @failure_callbacks << args.shift
  end
end
on_ignore(*args, &block) click to toggle source

Adds a callback that runs if the export is already running

# File lib/exporter/export_metadata.rb, line 115
def on_ignore *args, &block
  if block_given?
    @ignore_callbacks << block
  else
    @ignore_callbacks << args.shift
  end
end
on_success(*args, &block) click to toggle source

Adds a callback that runs if the export is completed successfully

# File lib/exporter/export_metadata.rb, line 125
def on_success *args, &block
  if block_given?
    @success_callbacks << block
  else
    @success_callbacks << args.shift
  end
end