Configurable max_attempts for healthcheck
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||||
MAX_ATTEMPTS = 7
|
DEFAULT_MAX_ATTEMPTS = 7
|
||||||
|
|
||||||
class HealthcheckError < StandardError; end
|
class HealthcheckError < StandardError; end
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
|||||||
|
|
||||||
target = "Health check against #{MRSK.config.healthcheck["path"]}"
|
target = "Health check against #{MRSK.config.healthcheck["path"]}"
|
||||||
attempt = 1
|
attempt = 1
|
||||||
|
max_attempts = MRSK.config.healthcheck["max_attempts"] || DEFAULT_MAX_ATTEMPTS
|
||||||
|
|
||||||
begin
|
begin
|
||||||
status = capture_with_info(*MRSK.healthcheck.curl)
|
status = capture_with_info(*MRSK.healthcheck.curl)
|
||||||
@@ -23,7 +24,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
|||||||
raise HealthcheckError, "#{target} failed with status #{status}"
|
raise HealthcheckError, "#{target} failed with status #{status}"
|
||||||
end
|
end
|
||||||
rescue SSHKit::Command::Failed
|
rescue SSHKit::Command::Failed
|
||||||
if attempt <= MAX_ATTEMPTS
|
if attempt <= max_attempts
|
||||||
info "#{target} failed to respond, retrying in #{attempt}s..."
|
info "#{target} failed to respond, retrying in #{attempt}s..."
|
||||||
sleep attempt
|
sleep attempt
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user