class Judges::Download

License
MIT
Copyright
Copyright © 2024-2025 Yegor Bugayenko
Author

Yegor Bugayenko (yegor256@gmail.com)
are not supposed to instantiate it yourself.
This class is instantiated by the bin/judge command line interface. You
The download command.

def initialize(loog)

Parameters:
  • loog (Loog) -- Logging facility
def initialize(loog)
  @loog = loog
end

def run(opts, args)

Raises:
  • (RuntimeError) - If not exactly two arguments provided

Parameters:
  • args (Array) -- List of command line arguments
  • opts (Hash) -- Command line options (start with '--')
def run(opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  jname = args[0]
  path = args[1]
  name = File.basename(path)
  baza = BazaRb.new(
    opts['host'], opts['port'].to_i, opts['token'],
    ssl: opts['ssl'],
    timeout: (opts['timeout'] || 30).to_i,
    loog: @loog,
    retries: (opts['retries'] || 3).to_i
  )
  elapsed(@loog, level: Logger::INFO) do
    id = baza.durable_find(jname, name)
    if id.nil?
      @loog.info("Durable '#{name}' not found in '#{jname}'")
      return
    end
    @loog.info("Durable ##{id} ('#{name}') found in '#{jname}'")
    baza.durable_lock(id, opts['owner'] || 'default')
    begin
      baza.durable_load(id, path)
      size = File.size(path)
      throw :"👍 Downloaded durable ##{id} to #{path} (#{size} bytes)"
    ensure
      baza.durable_unlock(id, opts['owner'] || 'default')
    end
  end
end