Module: Dash::Cli::Healthcheck::Poller

Extended by:
Poller
Included in:
Poller
Defined in:
lib/dash/cli/healthcheck/poller.rb

Constant Summary collapse

NO_HEALTHCHECK =
Dash::Commands::Base::NO_HEALTHCHECK

Instance Method Summary collapse

Instance Method Details

#wait_for_healthy(role:, &block) ⇒ Object

The wait itself happens on the host now (Dash::Commands::App#wait_for_ready), which returns the moment the status is one this poller accepts and otherwise waits out the deadline it is given. So the block is called once for the wait - and once more only to confirm an unchecked container is still running after its readiness delay. Every decision below is the one the client-side poll made, in the same words; what shrank is the number of round trips it took to reach them.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dash/cli/healthcheck/poller.rb', line 12

def wait_for_healthy(role:, &block)
  attempt = 1
  timeout_at = Time.now + DASH.config.deploy_timeout
  readiness_delay = role.readiness_delay

  begin
    status = block.call(:wait, seconds_left(timeout_at))

    if unchecked?(status)
      ensure_no_healthcheck_drift(role, status)

      if docker_state(status) == "running"
        announce_missing_gate(role, readiness_delay)

        # Wait for the readiness delay and confirm it is still running
        if readiness_delay > 0
          sleep readiness_delay
          status = block.call(:confirm)
          ensure_no_healthcheck_drift(role, status)
        end
      end
    end

    unless acceptable?(status)
      raise Dash::Cli::Healthcheck::Error, "container not ready after #{DASH.config.deploy_timeout} seconds (#{status})"
    end
  rescue Dash::Cli::Healthcheck::Error => e
    time_left = timeout_at - Time.now
    if time_left > 0
      sleep_for = [ attempt, time_left ].min
      elapsed = DASH.config.deploy_timeout - time_left
      info "Container not ready yet, retrying in #{sleep_for.ceil}s (#{elapsed.round}s elapsed, #{time_left.round}s left)"
      sleep sleep_for
      attempt += 1
      retry
    else
      raise
    end
  end

  info "Container is healthy!"
end