Class: RightScale::BaseRetryClient
- Defined in:
- lib/right_agent/clients/base_retry_client.rb
Overview
Abstract base client for creating RightNet and RightApi clients with retry capability Requests are automatically retried to overcome connectivity failures A status callback is provided so that the user of the client can take action (e.g., queue requests) when connectivity is lost Health checks are sent periodically to try to recover from connectivity failures
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_RECONNECT_INTERVAL =
Interval between reconnect attempts
15
- DEFAULT_OPEN_TIMEOUT =
Default time to wait for HTTP connection to open
2
- DEFAULT_REQUEST_TIMEOUT =
Default time to wait for response from request, which is chosen to be 5 seconds greater than the response timeout inside the RightNet router
35
- DEFAULT_RETRY_INTERVALS =
Default interval between successive retries and default maximum elapsed time until stop retrying These are chosen to be consistent with the retry sequencing for RightNet retryable requests (per :retry_interval and :retry_timeout agent deployer configuration parameters for RightNet router), so that if the retrying happens within the router, it will not retry here
[4, 12, 36]
- DEFAULT_RETRY_TIMEOUT =
25
- PERMITTED_STATE_TRANSITIONS =
{ :pending => [:pending, :connected, :disconnected, :failed, :closed], :connected => [:connected, :disconnected, :failed, :closing, :closed], :disconnected => [:connected, :disconnected, :failed, :closed], :failed => [:failed, :closed], :closing => [:closing, :closed], :closed => [:closed] }
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
State of this client: :pending, :connected, :disconnected, :failed, :closing, :closed.
Instance Method Summary collapse
-
#close(scope = :all) ⇒ TrueClass
Take any actions necessary to quiesce client interaction in preparation for agent termination but allow any active requests to complete.
-
#communicated { ... } ⇒ TrueClass
Set callback for each successful communication excluding health checks Multiple callbacks are supported.
-
#init(type, auth_client, options) ⇒ Boolean
Set configuration of this client and initialize HTTP access.
-
#stats(reset = false) ⇒ Hash
Current statistics for this client.
-
#status {|type, status| ... } ⇒ Symbol
Record callback to be notified of status changes Multiple callbacks are supported.
Instance Attribute Details
#state ⇒ Object
State of this client: :pending, :connected, :disconnected, :failed, :closing, :closed
53 54 55 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 53 def state @state end |
Instance Method Details
#close(scope = :all) ⇒ TrueClass
Take any actions necessary to quiesce client interaction in preparation for agent termination but allow any active requests to complete
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 141 def close(scope = :all) if scope == :receive && state == :connected self.state = :closing else self.state = :closed @reconnect_timer.cancel if @reconnect_timer @reconnect_timer = nil end close_http_client("terminating") true end |
#communicated { ... } ⇒ TrueClass
Set callback for each successful communication excluding health checks Multiple callbacks are supported
127 128 129 130 131 132 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 127 def communicated(&callback) raise ArgumentError, "Block missing" unless callback @communicated_callbacks ||= [] @communicated_callbacks << callback true end |
#init(type, auth_client, options) ⇒ Boolean
Set configuration of this client and initialize HTTP access
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 85 def init(type, auth_client, ) raise ArgumentError, "Auth client does not support server type #{type.inspect}" unless auth_client.respond_to?(type.to_s + "_url") raise ArgumentError, ":api_version option missing" unless [:api_version] @type = type @auth_client = auth_client @http_client = nil @status_callbacks = [] = .dup [:server_name] ||= type.to_s [:open_timeout] ||= DEFAULT_OPEN_TIMEOUT [:request_timeout] ||= DEFAULT_REQUEST_TIMEOUT [:retry_timeout] ||= DEFAULT_RETRY_TIMEOUT [:retry_intervals] ||= DEFAULT_RETRY_INTERVALS [:reconnect_interval] ||= DEFAULT_RECONNECT_INTERVAL reset_stats @state = :pending create_http_client enable_use if check_health == :connected state == :connected end |
#stats(reset = false) ⇒ Hash
Current statistics for this client
163 164 165 166 167 168 169 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 163 def stats(reset = false) stats = {} @stats.each { |k, v| stats[k] = v.all } stats["response time"] = @stats["requests sent"].avg_duration reset_stats if reset stats end |
#status {|type, status| ... } ⇒ Symbol
Record callback to be notified of status changes Multiple callbacks are supported
114 115 116 117 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 114 def status(&callback) @status_callbacks << callback if callback state end |