Module: Kamal::Cli::Healthcheck::Poller
Constant Summary collapse
- TRAEFIK_UPDATE_DELAY =
5
Instance Method Summary collapse
- #wait_for_healthy(pause_after_ready: false, &block) ⇒ Object
- #wait_for_unhealthy(pause_after_ready: false, &block) ⇒ Object
Instance Method Details
#wait_for_healthy(pause_after_ready: false, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kamal/cli/healthcheck/poller.rb', line 7 def wait_for_healthy(pause_after_ready: false, &block) attempt = 1 max_attempts = KAMAL.config.healthcheck["max_attempts"] begin case status = block.call when "healthy" sleep TRAEFIK_UPDATE_DELAY if pause_after_ready when "running" # No health check configured sleep KAMAL.config.readiness_delay if pause_after_ready else raise Kamal::Cli::Healthcheck::Error, "container not ready (#{status})" end rescue Kamal::Cli::Healthcheck::Error => e if attempt <= max_attempts info "#{e.}, retrying in #{attempt}s (attempt #{attempt}/#{max_attempts})..." sleep attempt attempt += 1 retry else raise end end info "Container is healthy!" end |
#wait_for_unhealthy(pause_after_ready: false, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kamal/cli/healthcheck/poller.rb', line 34 def wait_for_unhealthy(pause_after_ready: false, &block) attempt = 1 max_attempts = KAMAL.config.healthcheck["max_attempts"] begin case status = block.call when "unhealthy" sleep TRAEFIK_UPDATE_DELAY if pause_after_ready else raise Kamal::Cli::Healthcheck::Error, "container not unhealthy (#{status})" end rescue Kamal::Cli::Healthcheck::Error => e if attempt <= max_attempts info "#{e.}, retrying in #{attempt}s (attempt #{attempt}/#{max_attempts})..." sleep attempt attempt += 1 retry else raise end end info "Container is unhealthy!" end |