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
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 142 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
128 129 130 131 132 133 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 128 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 86 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 = [] @options = .dup @options[:server_name] ||= type.to_s @options[:open_timeout] ||= DEFAULT_OPEN_TIMEOUT @options[:request_timeout] ||= DEFAULT_REQUEST_TIMEOUT @options[:retry_timeout] ||= DEFAULT_RETRY_TIMEOUT @options[:retry_intervals] ||= DEFAULT_RETRY_INTERVALS @options[: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 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 163 def stats(reset = false) stats = {} @stats.each { |k, v| stats[k] = v.all } reset_stats if reset stats end |
#status {|type, status| ... } ⇒ Symbol
Record callback to be notified of status changes Multiple callbacks are supported
115 116 117 118 |
# File 'lib/right_agent/clients/base_retry_client.rb', line 115 def status(&callback) @status_callbacks << callback if callback state end |