Sha256: 77838d1421a1ba87b06da200d3674d955fe4c526490fd7b92b6cfdfe90fcfad1

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'logger'
require 'pathname'
require 'fileutils'
require 'zlib'
require 'net/ftp'

require 'pg'

require 'pg_export/version'
require 'pg_export/logging'
require 'pg_export/configuration'
require 'pg_export/errors'
require 'pg_export/dump'
require 'pg_export/actions'
require 'pg_export/ftp_service'
require 'pg_export/ftp_service/connection'

class PgExport
  include Logging

  def initialize
    @config = Configuration.new
    yield config if block_given?
    config.validate
    @dump = Dump.new(config.database, config.dumpfile_dir)
  end

  def initialize_ftp_service
    self.ftp_service = FtpService.new(config.ftp_params)
  end

  def call
    t = []
    t << Thread.new { perform_local_job }
    t << Thread.new { initialize_ftp_service }
    t.each(&:join)
    perform_ftp_job
    self
  end

  private

  attr_reader :config, :dump
  attr_accessor :ftp_service

  def perform_local_job
    CreateDump.new(dump).call
    CompressDump.new(dump).call
    RemoveOldDumps.new(dump, config.keep_dumps).call
  end

  def perform_ftp_job
    SendDumpToFtp.new(dump, ftp_service).call
    RemoveOldDumpsFromFtp.new(dump, ftp_service, config.keep_ftp_dumps).call
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pg_export-0.1.3 lib/pg_export.rb
pg_export-0.1.2 lib/pg_export.rb
pg_export-0.1.1 lib/pg_export.rb
pg_export-0.1.0 lib/pg_export.rb