forked from basecamp/kamal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request basecamp#219 from basecamp/docker-health-checks
- Loading branch information
Showing
13 changed files
with
183 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Mrsk::Utils::HealthcheckPoller | ||
TRAEFIK_HEALTHY_DELAY = 1 | ||
|
||
class HealthcheckError < StandardError; end | ||
|
||
class << self | ||
def wait_for_healthy(pause_after_ready: false, &block) | ||
attempt = 1 | ||
max_attempts = MRSK.config.healthcheck["max_attempts"] | ||
|
||
begin | ||
case status = block.call | ||
when "healthy" | ||
sleep TRAEFIK_HEALTHY_DELAY if pause_after_ready | ||
when "running" # No health check configured | ||
sleep MRSK.config.readiness_delay if pause_after_ready | ||
else | ||
raise HealthcheckError, "container not ready (#{status})" | ||
end | ||
rescue HealthcheckError => e | ||
if attempt <= max_attempts | ||
info "#{e.message}, retrying in #{attempt}s (attempt #{attempt}/#{max_attempts})..." | ||
sleep attempt | ||
attempt += 1 | ||
retry | ||
else | ||
raise | ||
end | ||
end | ||
|
||
info "Container is healthy!" | ||
end | ||
|
||
private | ||
def info(message) | ||
SSHKit.config.output.info(message) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.