Class: Judges::Pull

Inherits:
Object show all
Defined in:
lib/judges/commands/pull.rb

Overview

The pull command.

This class is instantiated by the bin/judge command line interface. You are not supposed to instantiate it yourself.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Pull

Returns a new instance of Pull.



22
23
24
# File 'lib/judges/commands/pull.rb', line 22

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object

Run it (it is supposed to be called by the bin/judges script.

Parameters:

  • opts (Hash)

    Command line options (start with ‘–’)

  • args (Array)

    List of command line arguments



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/judges/commands/pull.rb', line 29

def run(opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  fb = Factbase.new
  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
  )
  name = args[0]
  elapsed(@loog, level: Logger::INFO) do
    if baza.name_exists?(name)
      baza.lock(name, opts['owner'])
      begin
        jid = baza.recent(name)
        unless baza.exit_code(jid).zero?
          @loog.warn("STDOUT of the job ##{jid} (from the server):\n#{baza.stdout(jid)}")
          raise "The job ##{jid} ('#{name}') is broken, maybe you should expire it"
        end
        fb.import(baza.pull(wait(name, baza, jid, opts['wait'])))
        Judges::Impex.new(@loog, args[1]).export(fb)
      rescue StandardError => e
        baza.unlock(name, opts['owner'])
        raise e
      end
      throw :"Pulled #{fb.size} facts by the name '#{name}'"
    else
      throw :"There is nothing to pull, the name '#{name}' is absent on the server"
    end
  end
end