class Mamiya::Agent::Tasks::Fetch

Public Instance Methods

run() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 11
def run
  prepare_destination
  take_interval

  logger.info "Fetching #{application}/#{package}"
  step.run!

  order_cleaning
rescue Mamiya::Storages::Abstract::AlreadyFetched
  logger.info "It has already fetched; skipping."
end

Private Instance Methods

application() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 44
def application
  task['app']
end
destination() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 52
def destination
  @destination ||= File.join(packages_dir, application)
end
order_cleaning() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 40
def order_cleaning
  task_queue.enqueue(:clean, {})
end
package() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 48
def package
  task['pkg']
end
packages_dir() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 56
def packages_dir
  @packages_dir ||= config && config[:packages_dir]
end
prepare_destination() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 33
def prepare_destination
  unless File.exist?(destination)
    @logger.info "Creating #{destination}"
    FileUtils.mkdir_p(destination)
  end
end
step() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 60
def step
  @step ||= Mamiya::Steps::Fetch.new(
    application: application,
    package: package,
    destination: destination,
    config: config,
    logger: logger,
  )
end
take_interval() click to toggle source
# File lib/mamiya/agent/tasks/fetch.rb, line 25
def take_interval
  fetch_sleep = config[:fetch_sleep]
  wait = rand(fetch_sleep)

  @logger.info "Sleeping #{wait} sec before starting fetch"
  rand(wait)
end