Sha256: 2057c7750c4f733b3a525d9d911b436d24536611fe40ff5b969288d9404507c5

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'logger'
require 'tempfile'
require 'zlib'
require 'net/ftp'
require 'forwardable'

require 'pg_export/version'
require 'pg_export/logging'
require 'pg_export/errors'
require 'pg_export/configuration'
require 'pg_export/concurrency'
require 'pg_export/entities/dump/size_human'
require 'pg_export/entities/dump/base'
require 'pg_export/entities/sql_dump'
require 'pg_export/entities/compressed_dump'
require 'pg_export/services/ftp_service'
require 'pg_export/services/ftp_service/connection'
require 'pg_export/services/utils'
require 'pg_export/services/dump_storage'

class PgExport
  include Concurrency

  def initialize
    @config = Configuration.new
    yield config if block_given?
    config.validate
  end

  def call
    concurrently do |job|
      job << create_dump
      job << initialize_dump_storage
    end
    dump_storage.upload(dump)
    dump_storage.remove_old(keep: config.keep_dumps)
    self
  end

  private

  attr_reader :config
  attr_accessor :dump, :dump_storage

  def initialize_dump_storage
    ftp_service = FtpService.new(config.ftp_params)
    self.dump_storage = DumpStorage.new(ftp_service, config.database)
  end

  def create_dump
    sql_dump = Utils.create_dump(config.database)
    compressed_dump = Utils.compress(sql_dump)
    self.dump = compressed_dump
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.3.2 lib/pg_export.rb
pg_export-0.3.1 lib/pg_export.rb