Remove `stop_wait_time` and `readiness_timeout` from the root config and remove `deploy_timeout` and `drain_timeout` from the proxy config. Instead we'll just have `deploy_timeout` and `drain_timeout` in the root config. For roles that run the proxy, they are passed to the kamal-proxy deploy command. Once that returns we can assume the container is ready to shut down. For other roles, we'll use the `deploy_timeout` when polling the container to see if it is ready and the `drain_timeout` when stopping the container.
43 lines
1.1 KiB
Ruby
43 lines
1.1 KiB
Ruby
module Kamal::Cli::Healthcheck::Poller
|
|
extend self
|
|
|
|
def wait_for_healthy(role, &block)
|
|
attempt = 1
|
|
timeout_at = Time.now + KAMAL.config.deploy_timeout
|
|
readiness_delay = KAMAL.config.readiness_delay
|
|
|
|
begin
|
|
status = block.call
|
|
|
|
if status == "running"
|
|
# Wait for the readiness delay and confirm it is still running
|
|
if readiness_delay > 0
|
|
info "Container is running, waiting for readiness delay of #{readiness_delay} seconds"
|
|
sleep readiness_delay
|
|
status = block.call
|
|
end
|
|
end
|
|
|
|
unless %w[ running healthy ].include?(status)
|
|
raise Kamal::Cli::Healthcheck::Error, "container not ready after #{KAMAL.config.deploy_timeout} seconds (#{status})"
|
|
end
|
|
rescue Kamal::Cli::Healthcheck::Error => e
|
|
time_left = timeout_at - Time.now
|
|
if time_left > 0
|
|
sleep [ attempt, time_left ].min
|
|
attempt += 1
|
|
retry
|
|
else
|
|
raise
|
|
end
|
|
end
|
|
|
|
info "Container is healthy!"
|
|
end
|
|
|
|
private
|
|
def info(message)
|
|
SSHKit.config.output.info(message)
|
|
end
|
|
end
|