Class: SystemCheck::SimpleExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/system_check/simple_executor.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ SimpleExecutor

Returns a new instance of SimpleExecutor.

Parameters:

  • component (String)

    name of the component relative to the checks being executed

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/system_check/simple_executor.rb', line 17

def initialize(component)
  raise ArgumentError unless component.is_a? String

  @component = component
  @checks = Set.new
end

Instance Attribute Details

#checksArray<BaseCheck> (readonly)

classes of corresponding checks to be executed in the same order

Returns:

  • (Array<BaseCheck>)

    the current value of checks



12
13
14
# File 'lib/system_check/simple_executor.rb', line 12

def checks
  @checks
end

#componentString (readonly)

name of the component relative to the checks being executed

Returns:

  • (String)

    the current value of component



12
13
14
# File 'lib/system_check/simple_executor.rb', line 12

def component
  @component
end

Instance Method Details

#<<(check) ⇒ Object

Add a check to be executed

Parameters:

Raises:

  • (ArgumentError)


27
28
29
30
31
# File 'lib/system_check/simple_executor.rb', line 27

def <<(check)
  raise ArgumentError unless check.is_a?(Class) && check < BaseCheck

  @checks << check
end

#executeObject

Executes defined checks in the specified order and outputs confirmation or error information



34
35
36
37
38
39
40
41
42
# File 'lib/system_check/simple_executor.rb', line 34

def execute
  start_checking(component)

  @checks.each do |check|
    run_check(check)
  end

  finished_checking(component)
end

#run_check(check_klass) ⇒ Object

Executes a single check

Parameters:



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
# File 'lib/system_check/simple_executor.rb', line 47

def run_check(check_klass)
  print_display_name(check_klass)

  check = check_klass.new

  # When implements skip method, we run it first, and if true, skip the check
  if check.can_skip? && check.skip?
    $stdout.puts check.skip_reason.try(:color, :magenta) || check_klass.skip_reason.color(:magenta)
    return
  end

  # When implements a multi check, we don't control the output
  if check.multi_check?
    check.multi_check
    return
  end

  if check.check?
    print_check_pass(check_klass)
  else
    print_check_failure(check_klass)

    if check.can_repair?
      $stdout.print 'Trying to fix error automatically. ...'

      if check.repair!
        print_success
        return
      else
        print_failure
      end
    end

    check.show_error
  end
rescue StandardError => e
  $stdout.puts "Exception: #{e.message}".color(:red)
end