Class: Judges::Update
Overview
The update 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
-
#initialize(loog) ⇒ Update
constructor
Initialize.
-
#run(opts, args) ⇒ Object
Run the update command (called by the
bin/judgesscript).
Constructor Details
#initialize(loog) ⇒ Update
Initialize.
31 32 33 34 |
# File 'lib/judges/commands/update.rb', line 31 def initialize(loog) @loog = loog @start = Time.now end |
Instance Method Details
#run(opts, args) ⇒ Object
Run the update command (called by the bin/judges script).
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/judges/commands/update.rb', line 40 def run(opts, args) raise 'Exactly two arguments required' unless args.size == 2 dir = args[0] raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir) start = Time.now impex = Judges::Impex.new(@loog, args[1]) fb = impex.import(strict: false) fb = Factbase::Logged.new(fb, @loog) if opts['log'] = Judges::Options.new(opts['option']) if opts['options-file'] += Judges::Options.new( File.readlines(opts['options-file']) .compact .reject(&:empty?) .map { |ln| ln.strip.split('=', 1).map(&:strip).join('=') } ) @loog.debug("Options loaded from #{opts['options-file']}") end if .empty? @loog.debug('No options provided by the --option flag') else @loog.debug("The following options provided:\n\t#{.to_s.gsub("\n", "\n\t")}") end judges = Judges::Judges.new(dir, opts['lib'], @loog, start:, shuffle: opts['shuffle'], boost: opts['boost']) c = 0 churn = Factbase::Churn.new errors = [] elapsed(@loog, level: Logger::INFO) do loop do c += 1 if c > 1 @loog.info("\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...") end delta = cycle(opts, judges, fb, , start, errors) churn += delta impex.export(fb) if delta.zero? @loog.info("The update cycle ##{c} has made no changes to the factbase, let's stop") break end if !opts['max-cycles'].nil? && c >= opts['max-cycles'] @loog.info("Too many cycles already, as set by --max-cycles=#{opts['max-cycles']}, breaking") break end if opts['fail-fast'] && !errors.empty? @loog.info("Due to #{errors.count} errors we must stop at the update cycle ##{c}") break end @loog.info("The cycle #{c} did #{delta}") end throw :"👍 Update completed in #{c} cycle(s), did #{churn}" end return unless opts['summary'] summarize(fb, churn, errors, start, c) impex.export(fb) end |