class ODisk::Fetcher

Fetches a remote Digest JSON document and creates a Digest Object from it. That Digest is then passed on to a Opee::Collector.

Public Class Methods

new(options={}) click to toggle source
Calls superclass method
# File lib/odisk/fetcher.rb, line 17
def initialize(options={})
  @ftp = nil
  super(options)
end

Public Instance Methods

close() click to toggle source
Calls superclass method
# File lib/odisk/fetcher.rb, line 27
def close()
  super()
  @ftp.close_channel() unless @ftp.nil?
  @ftp = nil
end
set_options(options) click to toggle source
Calls superclass method
# File lib/odisk/fetcher.rb, line 22
def set_options(options)
  super(options)
  @collector = options[:collector]
end

Private Instance Methods

fetch(job) click to toggle source
# File lib/odisk/fetcher.rb, line 35
def fetch(job)
  top = (job.path.nil? || job.path.empty?) ? $remote.dir : ::File.join($remote.dir, job.path)
  path = ::File.join(top, '.odisk', 'digest.json')
  ::Opee::Env.info("fetch digest \"#{path}\"")
  @ftp = Net::SFTP.start($remote.host, $remote.user) if @ftp.nil?
  begin
    json = @ftp.download!(path)
    files = @ftp.dir.entries(top).map {|e| e.name }
    job.remote_digest = Oj.load(json, mode: :object)
    missing = []
    job.remote_digest.entries.each { |e| missing << e.name unless (files.include?(e.name + '.gpg') ||
                                                                   files.include?(e.name) ||
                                                                   e.is_a?(::ODisk::Link) ||
                                                                   e.removed) }
    unless ::ODisk::Planner::Step::REMOTE == $master
      missing.each { |name| job.remote_digest.delete(name) }
    end
  rescue Exception
    job.remote_digest = nil
  end
  @collector.ask(:collect, job, :fetcher) unless @collector.nil?
  ::Opee::Env.debug("#{Oj.dump(job.remote_digest, indent: 2)})")
end