Commit 53f71368 authored by Alain Takoudjou's avatar Alain Takoudjou

NXD lib/tasks/gitlab/check: Exit with non-zero code, if something failed in a check task

This is handy for monitoring tools, which could e.g. periodically call check
tasks and instead of parsing output, rely on exit code.

The way we detect if something failed is via hooking into String#red, and if
anything was ever printed in red - that's an error.
parent 5461ac4c
......@@ -2,6 +2,17 @@ module SystemCheck
module Helpers
include ::Gitlab::TaskHelpers
# if we ever print anything in red - that's an error
$check_failed = false
class String
alias_method :orig_red, :red
def red(*args)
$check_failed = true
orig_red(*args)
end
end
# Display a message telling to fix and rerun the checks
def fix_and_rerun
$stdout.puts ' Please fix the error above and rerun the checks.'.color(:red)
......@@ -24,8 +35,9 @@ module SystemCheck
# @deprecated This will no longer be used when all checks were executed using SystemCheck
def finished_checking(component)
$stdout.puts ''
$stdout.puts "Checking #{component.color(:yellow)} ... #{'Finished'.color(:green)}"
$stdout.puts "Checking #{component.color(:yellow)} ... #{$check_failed ? "Failed".color(:red) : "OK".color(:green)}"
$stdout.puts ''
exit 1 if $check_failed
end
# @deprecated This will no longer be used when all checks were executed using SystemCheck
......
module SystemCheck
# if we ever print anything in red - that's an error
$check_failed = false
class String
alias_method :orig_red, :red
def red(*args)
$check_failed = true
orig_red(*args)
end
end
# Simple Executor is current default executor for GitLab
# It is a simple port from display logic in the old check.rake
#
......@@ -116,8 +128,9 @@ module SystemCheck
# @param [String] component name of the component relative to the checks being executed
def finished_checking(component)
$stdout.puts ''
$stdout.puts "Checking #{component.color(:yellow)} ... #{'Finished'.color(:green)}"
$stdout.puts "Checking #{component.color(:yellow)} ... #{$check_failed ? "Failed".color(:red) : "OK".color(:green)}"
$stdout.puts ''
exit 1 if $check_failed
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment