Class: Judges::Push

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

Overview

The push command.

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

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Push

Initialize.

Parameters:

  • loog (Loog)

    Logging facility



24
25
26
# File 'lib/judges/commands/push.rb', line 24

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(opts, args) ⇒ Object

Run the push command (called by the bin/judges script).

Parameters:

  • opts (Hash)

    Command line options (start with ‘–’)

  • args (Array)

    List of command line arguments

Raises:

  • (RuntimeError)

    If not exactly two arguments provided



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/judges/commands/push.rb', line 32

def run(opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  name = args[0]
  fb = Judges::Impex.new(@loog, args[1]).import
  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,
    compress: opts.fetch('zip', true)
  )
  elapsed(@loog, level: Logger::INFO) do
    baza.lock(name, opts['owner'])
    begin
      id = baza.push(name, fb.export, opts['meta'] || [])
      throw :"👍 Pushed #{fb.size} facts, job ID is #{id}"
    ensure
      baza.unlock(name, opts['owner'])
    end
  end
end