2017-02-12 18:33:31 -05:00
|
|
|
module SystemCheck
|
2017-02-13 03:45:39 -05:00
|
|
|
# Simple Executor is current default executor for GitLab
|
|
|
|
# It is a simple port from display logic in the old check.rake
|
|
|
|
#
|
|
|
|
# There is no concurrency level and the output is progressively
|
|
|
|
# printed into the STDOUT
|
2017-05-31 14:45:00 -04:00
|
|
|
#
|
|
|
|
# @attr_reader [Array<BaseCheck>] checks classes of corresponding checks to be executed in the same order
|
|
|
|
# @attr_reader [String] component name of the component relative to the checks being executed
|
|
|
|
class SimpleExecutor
|
|
|
|
attr_reader :checks
|
|
|
|
attr_reader :component
|
|
|
|
|
|
|
|
# @param [String] component name of the component relative to the checks being executed
|
|
|
|
def initialize(component)
|
|
|
|
raise ArgumentError unless component.is_a? String
|
|
|
|
|
|
|
|
@component = component
|
|
|
|
@checks = Set.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add a check to be executed
|
|
|
|
#
|
|
|
|
# @param [BaseCheck] check class
|
|
|
|
def <<(check)
|
2017-09-03 21:58:54 -04:00
|
|
|
raise ArgumentError unless check.is_a?(Class) && check < BaseCheck
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2017-05-31 14:45:00 -04:00
|
|
|
@checks << check
|
|
|
|
end
|
|
|
|
|
2017-02-13 03:45:39 -05:00
|
|
|
# Executes defined checks in the specified order and outputs confirmation or error information
|
2017-02-12 18:33:31 -05:00
|
|
|
def execute
|
|
|
|
start_checking(component)
|
|
|
|
|
|
|
|
@checks.each do |check|
|
2017-05-25 10:16:25 -04:00
|
|
|
run_check(check)
|
2017-02-12 18:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
finished_checking(component)
|
|
|
|
end
|
|
|
|
|
2017-05-25 10:16:25 -04:00
|
|
|
# Executes a single check
|
|
|
|
#
|
2017-05-30 13:06:58 -04:00
|
|
|
# @param [SystemCheck::BaseCheck] check_klass
|
|
|
|
def run_check(check_klass)
|
|
|
|
$stdout.print "#{check_klass.display_name} ... "
|
2017-05-25 10:16:25 -04:00
|
|
|
|
2017-05-30 13:06:58 -04:00
|
|
|
check = check_klass.new
|
2017-05-25 10:16:25 -04:00
|
|
|
|
|
|
|
# When implements skip method, we run it first, and if true, skip the check
|
2017-05-30 13:06:58 -04:00
|
|
|
if check.can_skip? && check.skip?
|
2017-09-03 21:58:54 -04:00
|
|
|
$stdout.puts check.skip_reason.try(:color, :magenta) || check_klass.skip_reason.color(:magenta)
|
2017-05-25 10:16:25 -04:00
|
|
|
return
|
|
|
|
end
|
2017-05-30 13:06:58 -04:00
|
|
|
|
2017-05-25 19:46:54 -04:00
|
|
|
# When implements a multi check, we don't control the output
|
2017-08-24 13:01:22 -04:00
|
|
|
if check.multi_check?
|
2017-05-30 13:06:58 -04:00
|
|
|
check.multi_check
|
2017-05-25 19:46:54 -04:00
|
|
|
return
|
|
|
|
end
|
2017-05-25 10:16:25 -04:00
|
|
|
|
2017-05-30 13:06:58 -04:00
|
|
|
if check.check?
|
|
|
|
$stdout.puts check_klass.check_pass.color(:green)
|
2017-05-25 10:16:25 -04:00
|
|
|
else
|
2017-05-30 13:06:58 -04:00
|
|
|
$stdout.puts check_klass.check_fail.color(:red)
|
2017-05-25 10:16:25 -04:00
|
|
|
|
2017-05-30 13:06:58 -04:00
|
|
|
if check.can_repair?
|
2017-05-25 10:16:25 -04:00
|
|
|
$stdout.print 'Trying to fix error automatically. ...'
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-05-30 13:06:58 -04:00
|
|
|
if check.repair!
|
2017-05-25 10:16:25 -04:00
|
|
|
$stdout.puts 'Success'.color(:green)
|
|
|
|
return
|
|
|
|
else
|
|
|
|
$stdout.puts 'Failed'.color(:red)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-30 13:06:58 -04:00
|
|
|
check.show_error
|
2017-05-25 10:16:25 -04:00
|
|
|
end
|
2017-06-27 11:41:58 -04:00
|
|
|
rescue StandardError => e
|
|
|
|
$stdout.puts "Exception: #{e.message}".color(:red)
|
2017-05-25 10:16:25 -04:00
|
|
|
end
|
|
|
|
|
2017-02-12 18:33:31 -05:00
|
|
|
private
|
|
|
|
|
2017-02-13 03:45:39 -05:00
|
|
|
# Prints header content for the series of checks to be executed for this component
|
|
|
|
#
|
|
|
|
# @param [String] component name of the component relative to the checks being executed
|
2017-02-12 18:33:31 -05:00
|
|
|
def start_checking(component)
|
2017-02-13 03:45:39 -05:00
|
|
|
$stdout.puts "Checking #{component.color(:yellow)} ..."
|
|
|
|
$stdout.puts ''
|
2017-02-12 18:33:31 -05:00
|
|
|
end
|
|
|
|
|
2017-02-13 03:45:39 -05:00
|
|
|
# Prints footer content for the series of checks executed for this component
|
|
|
|
#
|
|
|
|
# @param [String] component name of the component relative to the checks being executed
|
2017-02-12 18:33:31 -05:00
|
|
|
def finished_checking(component)
|
2017-02-13 03:45:39 -05:00
|
|
|
$stdout.puts ''
|
|
|
|
$stdout.puts "Checking #{component.color(:yellow)} ... #{'Finished'.color(:green)}"
|
|
|
|
$stdout.puts ''
|
2017-02-12 18:33:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|