From cb3c5a53f49de022052c333b9424b4358941ee28 Mon Sep 17 00:00:00 2001 From: Arturo Ojeda Date: Sat, 8 Apr 2023 19:52:53 -0600 Subject: [PATCH] Configurable max_attempts for healthcheck --- lib/mrsk/cli/healthcheck.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/cli/healthcheck.rb b/lib/mrsk/cli/healthcheck.rb index 3fda7754..94950373 100644 --- a/lib/mrsk/cli/healthcheck.rb +++ b/lib/mrsk/cli/healthcheck.rb @@ -1,5 +1,5 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base - MAX_ATTEMPTS = 7 + DEFAULT_MAX_ATTEMPTS = 7 class HealthcheckError < StandardError; end @@ -13,6 +13,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base target = "Health check against #{MRSK.config.healthcheck["path"]}" attempt = 1 + max_attempts = MRSK.config.healthcheck["max_attempts"] || DEFAULT_MAX_ATTEMPTS begin 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}" end rescue SSHKit::Command::Failed - if attempt <= MAX_ATTEMPTS + if attempt <= max_attempts info "#{target} failed to respond, retrying in #{attempt}s..." sleep attempt attempt += 1